java - Replace Last Occurrence of a character in a string -
this question has answer here:
- replace last part of string 9 answers
i having string this
"position, fix, dial"
i want replace last double quote(") escape double quote(\")
the result of string
"position, fix, dial\"
how can this. aware of replacing first occurrence of string. don't know how replace last occurrence of string
string str = "\"position, fix, dial\""; int ind = str.lastindexof("\""); if( ind>=0 ) str = new stringbuilder(str).replace(ind, ind+1,"\\\"").tostring(); system.out.println(str);
Comments
Post a Comment