Hi,
I have the following program that is supposed to detect a subsequence from a String (that contains $ signs) and remove it. This is a bit tricky, since because of $ signs, the replaceAll method for String does not work. When I use replaceAll for removing the part of the String w/ no $ signs, replaceAll works perfectly, but my code needs to cover the $ signs as well.
So far, except for replaceAll, I have tried the following, with the intent to first remove $ signs from only that specific sequence in the String (in this case from $d $e $f) and then remove the remaining, which is d e f.
If anyone has any idea on this, I would greatly appreciate it!
Looking forward to your help!
public class StringDivider {
public static void main(String [] args)
{
String symbols = "$a $b $c $d $e $f $g $h $i $j $k l m n o p";
String removeSymbols = "$d $e $f";
int startIndex = symbols.indexOf(removeSymbols);
int endIndex = startIndex + removeSymbols.length()-1;
for(int i=startIndex;i<endIndex+1;i++)
{
if(symbols.charAt(i)=='$')
{
//not sure what to do here, I tried using replace(oldChar, newChar), but I couldn't achieve my point, which is to
//delete $ signs from the specific sequence only (as opposed to all the $ signs)
}
}
System.out.println(symbols);
}
}