+ 1
I have a string "^test^^^^^^test" i want the answer as "^test^test"
^ is variable
3 Respostas
+ 1
Please explain better so we can help you
+ 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"
+ 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