java - How to replace a repeating char at only a particular place in String? -
i have string : hi/i/jack/there
which contains multiple '/' between values. , these values not of fixed length(can length)
and need replace second occurrence of '/' string means output should be.. hi/iamjack/there
how should achieve this? tried string.replace , logic it's replacing occurrences need 2nd occurrence replace. , i'm restricted use string only(not stringbuilder or else)
count /
each element in string
string s = "hi/i/jack/there"; for(int i=0,count=0;i<s.length();i++) { if(s.charat(i)=='/')// if i'th element '/' { count++; if(count==2)//it's second '/' { //separate 2 part second '/' , add want @ middle s = s.substring(0,i) + "am" +s.substring(i+1,s.length()); } } }
Comments
Post a Comment