Bug 12907 - string manipulation with method: padleft or padright isn't working!
Summary: string manipulation with method: padleft or padright isn't working!
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: C# Binding ()
Version: 3.0.x
Hardware: PC Linux
: --- normal
Target Milestone: master
Assignee: Mike Krüger
Depends on:
Reported: 2013-06-26 13:31 UTC by Frederik
Modified: 2013-06-26 16:52 UTC (History)
1 user (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Frederik 2013-06-26 13:31:27 UTC

What I try to do, is to manipulate a string with the "method" PadLeft or PadRight. None of them seems to work! An error I also not have & and I think mine code is OK!

I did try this into a simple console project: (See source code below)

Example code 1:
string str = "Align this text";
char pad = '_';
Console.WriteLine (str .PadLeft (15,pad));

Example code 2:
string myString;
myString = "Align this text";
myString .PadRight (10,'i');
Console.WriteLine ("{0}",myString);

None of the code above is working...Did try this also into the graphical environment, with a textbox or label and it seems also not working!

Don't know if it's a "bug" or do I programme something wrong???

Thanx and best regards,
Comment 1 Mikayla Hutchinson [MSFT] 2013-06-26 16:52:48 UTC
It's not a bug in Mono, it's a bug in your code. FWIW, StackOverflow would have been a more appropriate place for this.

1) Your string is already 15 characters long so padding it to a length of 15 does nothing. See http://msdn.microsoft.com/en-us/library/system.string.padleft.aspx 

2) Strings in .NET/Mono are immutable, the methods on them return new strings. You are outputting the original string, not the padded one.