java - How can I read a String line by line and replace particular line with another particular String -
how can read string line line , replace particular line particular string?
example:
string mystring = "this" +"\nis" + "\nonly" + "\nthe" + "\nexample"; and want read them line line start top , replace each 1 such "this" ->> "newthis" "is" ->> "newis" , , on.
you can use split method:
string[] yourstringasarray = mystring.split("\n") then can iterate on array that:
for(string s : yourstringasarray){ s.replaceall("oldvalue", "newvalue") }
Comments
Post a Comment