c# - String.Replace not replacing the string during runtime -
the following line in below code doesn't cause effect:
string1.replace(string1.substring(firstchar, lastchar - firstchar), "##");
string1
remains unchanged , same index returned when using indexof.
while (firstchar != string1.lastindexof("test")) { firstchar = string1.indexof("test"); lastchar = string1.indexof(" "); using (streamwriter writer = new streamwriter("c:\\textfile1.txt")) { writer.writeline(string1.substring(firstchar, lastchar - firstchar)); writer.writeline(); writer.dispose(); } string1.replace(string1.substring(firstchar, lastchar - firstchar), "##"); }
change
string1.replace(string1.substring(firstchar, lastchar - firstchar), "##");
to
string1 = string1.replace(string1.substring(firstchar, lastchar - firstchar), "##");
string.replace
not alter original string, returns altered string it's return value.
Comments
Post a Comment