how to replace a character from string without using str replace method

Posted by Vibheesh under C# on 12/6/2011 | Points: 10 | Views : 964 | Status : [Member] | Replies : 2
For example in "welcome" string i want to replace last character of welcome.
i.e "e".if i use replace method it will replace all the instance of the (e).
can anyone write program for this




Responses

Posted by: RohiK on: 12/7/2011 [Member] Starter | Points: 25

Up
0
Down
Hi

try this


var theString = "WELCOME";
var aStringBuilder = new StringBuilder(theString);
aStringBuilder.Remove(6, 1);
aStringBuilder.Insert(6, "ee");
theString = aStringBuilder.ToString();

Happy Programming!!
Rohi

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

Posted by: Hmanjarawala on: 12/7/2011 [Member] Bronze | Points: 25

Up
0
Down
Hi,
here is another one

string str = "Welcome";
str = str.Substring(0, str.LastIndexOf('e')) + "ee";

Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

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

Login to post response