+ 1

I have a string "^test^^^^^^test" i want the answer as "^test^test"

^ is variable

15th Mar 2019, 6:51 PM
Abhishek Tak
Abhishek Tak - avatar
3 ответов
+ 1
Please explain better so we can help you
15th Mar 2019, 7:50 PM
JavaBobbo
JavaBobbo - avatar
+ 1
String a1 = "^Test^Test^^Test^^^^^^Test" I want to replace "^" with blank but the first "^" before any word should remain as it is for eg in the above string i should get output as : "^Test^Test^Test"
16th Mar 2019, 2:45 AM
Abhishek Tak
Abhishek Tak - avatar
+ 1
Sorry for late answer. This is a example how you could do it. In your main: String a1 = "^Test^Test^^Test^^^^^^Test"; a1 = remDup(a1.toCharArray()); System.out.println(a1); And use this method: static String remDup(char[] ch) { int c = 0; char p = ' '; for (int i = 0; i < ch.length; i++) if (p != ch[i]) { ch[c++] = ch[i]; p = ch[i]; } return new String(ch).substring(0, c); } This will remove duplicate characters
17th Mar 2019, 4:56 PM
JavaBobbo
JavaBobbo - avatar