I am trying to find a substring counter in a large string 10,000 characters long. Finally, I need to remove the entire substring. example s = abacacac, substr = ac, num of occurrence = 3and the final line - s = ab. My code is below, it is not efficient for data length of 10,000 characters.
int count =0;
while(s.contains(substr))
{
s= s.replaceFirst(substr,"");
count++;
}
source
share