Results 1 to 3 of 3
  1. #1
    Welko is offline Member
    Join Date
    May 2012
    Posts
    2
    Rep Power
    0

    Default Problems with "replaceAll"

    Here is my problem:

    Java Code:
    package test;
    
    public class Test {
    	public static void main(String[] args) {
    		String x = "4 + 2 * 5 ^  ( 3 - 1 *  (  3√8 )  /  (  2√ ( 8 / 2 *  2√4 )  )  * 2 )  - 4";
    		String toReplace = " ( 8 / 2 *  2√4 ) ";
    		String y = "8.0";
    		
    		x = x.replaceAll(toReplace, y);
    		
    		System.out.print(x);
    	}
    }
    I try to replace " ( 8 / 2 * 2√4 ) " by "8.0" in the string x, but that doesn't work. Is it because of the ""? Is it because of the brackets?

    Please, help me.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default Re: Problems with "replaceAll"

    Is it because of the "√"?
    Probably not.

    Is it because of the brackets?
    Do you mean the parentheses? Yes, they are metacharacters and need to be escaped.
    String Literals (The Java™ Tutorials > Essential Classes > Regular Expressions)
    Regular-Expressions.info - Regex Tutorial, Examples and Reference - Regexp Patterns

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Welko is offline Member
    Join Date
    May 2012
    Posts
    2
    Rep Power
    0

    Default Re: Problems with "replaceAll"

    Woah. Thank you very much!

    Now it works perfectly!

Similar Threads

  1. Replies: 1
    Last Post: 02-01-2012, 09:37 PM
  2. Replies: 5
    Last Post: 12-21-2011, 07:44 PM
  3. Replies: 0
    Last Post: 11-18-2011, 11:22 PM
  4. Replies: 2
    Last Post: 01-24-2009, 07:56 PM
  5. Replies: 1
    Last Post: 10-20-2008, 08:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •