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

Posted by Allemahesh under C# on 7/18/2013 | Points: 10 | Views : 1404 | Status : [Member] [MVP] | Replies : 3
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

Posted by: Satyapriyanayak on: 7/18/2013 [Member] [MVP] Silver | Points: 50

Up
0
Down

Resolved
string s1 = "11001010001010";

string s2 = s1 .Remove(0, 1);
string s3 = "0" + s2;
MessageBox.Show(s3.ToString());


If this post helps you mark it as answer
Thanks

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

Login to post response