format - Replace string where it has .rpt -
i want read string in java has like
xyz.rpt abcde.img erhteds.doc aqwer.rpt
and modify string has .rpt
in it. if string has .rpt
@ end need change .doc
output: xyz.doc abcde.img erhteds.doc aqwer.doc
the following code should replace last occurance of '.rpt' '.doc' if read line line
stringbuilder b = new stringbuilder(yourstring); b.replace(yourstring.lastindexof(".rpt"), yourstring.lastindexof(".rpt") + 1, ".doc" ); yourstring = b.tostring();
note throw exceptions if string doesn't contain '.rpt'
Comments
Post a Comment