|
-
Oct 30th, 2002, 02:47 AM
#1
Thread Starter
Frenzied Member
Why won't this string operation work?
string tS = "JOB !12 JAN 2002 ! 12:22:12";
tS.Replace("2","r");
Console.Write(tS);
the output is:
JOB !12 JAN 2002 ! 12:22:12
although the replace method should have replaced the 2 with r
HOWEVER
this one works
Console.Write(tS.Replace("2","r"));
Anyone has any suggestions???
best regards
Henrik
-
Oct 30th, 2002, 09:05 AM
#2
PowerPoster
You need to assign the result of the replace() method to a new string. When working with string objects, a new string is created everytime you make a change to the string. If you are doing alot of string manipualtion, read up on the StringBuilder class.
Code:
string myNewString = tS.Replace("2","r");
Console.Write(myNewString);
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|