Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Remove $%&* characters from a String

801912Oct 25 2007 — edited Oct 26 2007
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);
	}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 23 2007
Added on Oct 25 2007
4 comments
192 views