How to replace first char in a string c# [Resolved]

Posted by Allemahesh under C# on 7/18/2013 | Points: 10 | Views : 13497 | Status : [Member] [MVP] | Replies : 2
I have a string.
string str = "11001010001010";
Now I want to replace the first char 1 to 0 i.e. "01001010001010"
Can any one help me.




Responses

Posted by: Kundan64 on: 7/18/2013 [Member] Starter | Points: 50

Up
0
Down

Resolved
use this code:
string ReplaceCharacter(string s, char newvalue)

{
return newvalue + s.Substring(1);
}


This code will replace the First Character of you String with the value provided in 'newvalue' parameter.

Mark as Answer if its help you.

Allemahesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ssj_Kumar on: 7/18/2013 [Member] Starter | Points: 50

Up
0
Down

Resolved
string strValue = "11001010001010";
strValue = "0" + strValue.Substring(1, strValue.Length-1);

Regards,
Jayakumar Selvakani

Allemahesh, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response