does Trim() work??
-
When I run this,
using System;
namespace trim
{
public class trim
{
static void Main()
{
string str = "Senkwe ";
Console.WriteLine(str.Length);
str.Trim();
Console.WriteLine(str.Length);
}
}
}I get an output of 10 each time. Am I using trim improperly? I even tried specifying an array of characters to be reomoved ie
char[] myChars = {' '};
and it still didn't work. Any ideas? Regards Senkwe Just another wannabe code junky -
When I run this,
using System;
namespace trim
{
public class trim
{
static void Main()
{
string str = "Senkwe ";
Console.WriteLine(str.Length);
str.Trim();
Console.WriteLine(str.Length);
}
}
}I get an output of 10 each time. Am I using trim improperly? I even tried specifying an array of characters to be reomoved ie
char[] myChars = {' '};
and it still didn't work. Any ideas? Regards Senkwe Just another wannabe code junkyTrim returns the new string!
str=str.Trim();
should be the solution i got into this trap with the Registry-class: when you want to open a subkey you would write
key.open(location);
but instead the handle to the opened key is returned. so
key=key.open(location);
worked. in general: someone has to explain to me, what the idea behind this weired design is? this behaviour of returning the result looks to me like a static function (like Color.FromArgb()) - which Trim and this registry-open-function are not. i don't like that design - and obviously i'm not the only one, that was caught in that trap... :wq
-
Trim returns the new string!
str=str.Trim();
should be the solution i got into this trap with the Registry-class: when you want to open a subkey you would write
key.open(location);
but instead the handle to the opened key is returned. so
key=key.open(location);
worked. in general: someone has to explain to me, what the idea behind this weired design is? this behaviour of returning the result looks to me like a static function (like Color.FromArgb()) - which Trim and this registry-open-function are not. i don't like that design - and obviously i'm not the only one, that was caught in that trap... :wq
Thanks alot! Boy, that was so un-obvious to me. To make matters worse, the documentation had no real examples of how to use it. I agree that it is wierd and inconsistent. Thanks again Regards Senkwe Just another wannabe code junky
-
Thanks alot! Boy, that was so un-obvious to me. To make matters worse, the documentation had no real examples of how to use it. I agree that it is wierd and inconsistent. Thanks again Regards Senkwe Just another wannabe code junky
My guess as to why it works this way is that strings are immutable (can't be changed). So methods that apprear to change the string actually return a modified copy. The original string stays intact which is why you needed to assign the returned modified string to the orginal string variable (i.e. str = str.Trim();
-
My guess as to why it works this way is that strings are immutable (can't be changed). So methods that apprear to change the string actually return a modified copy. The original string stays intact which is why you needed to assign the returned modified string to the orginal string variable (i.e. str = str.Trim();
Exactly :) James Simplicity Rules!
-
Exactly :) James Simplicity Rules!
You really understand this stuff well ! Congrats Regardz Colin J Davies
Sonork ID 100.9197:Colin
"real Americans don't criticize their leaders - because they don't want the terrorists to win." -- Quote from Chris Losinger a real American"
-
You really understand this stuff well ! Congrats Regardz Colin J Davies
Sonork ID 100.9197:Colin
"real Americans don't criticize their leaders - because they don't want the terrorists to win." -- Quote from Chris Losinger a real American"
****Colin Davies wrote: You really understand this stuff well ! Congrats Thanks :) I try to be really good at what I do, currently that is C# and .NET :-D James Simplicity Rules!
-
****Colin Davies wrote: You really understand this stuff well ! Congrats Thanks :) I try to be really good at what I do, currently that is C# and .NET :-D James Simplicity Rules!
James T. Johnson wrote: I try to be really good at what I do, currently that is C# and .NET Thats a good attitude to have ! I hope you succeede ? Regardz Colin J Davies
Sonork ID 100.9197:Colin
"real Americans don't criticize their leaders - because they don't want the terrorists to win." -- Quote from Chris Losinger a real American"