Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: How to replace dollar signs with ""?

  1. #1
    Member
    Join Date
    Feb 2011
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to replace dollar signs with ""?

    I have a program that prompts the user for an entry and they could potentially enter in a lot of things, but I want to catch the dollar signs and convert them to "" in terms of strings. I've tried using the replace method on my string like:

    input.replace("$", "");

    But that obviously doesn't work. What can I do to achieve this? What if there are multiple dollar signs? Is there a method on String which I can call to replace all dollar signs?


  2. #2
    Member
    Join Date
    Oct 2011
    Posts
    42
    My Mood
    Sneaky
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Re: How to replace dollar signs with ""?

    Try
    String.replaceAll(String statement, String replacement)

    String (Java 2 Platform SE v1.4.2)

  3. #3
    Member
    Join Date
    Feb 2011
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to replace dollar signs with ""?

    Quote Originally Posted by Tsarin View Post
    Try
    String.replaceAll(String statement, String replacement)

    String (Java 2 Platform SE v1.4.2)
    I tried that...It still didn't work :\

    The string value doesn't become changed at all

  4. #4
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: How to replace dollar signs with ""?

    If you read the API for String you would notice that the replace methods return a new String with the replacement carried out.
    So all you need to do is assign the replaced version back to input.
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

Similar Threads

  1. Replies: 7
    Last Post: August 13th, 2011, 01:22 AM
  2. Replies: 6
    Last Post: November 12th, 2010, 04:40 AM
  3. Java says:"Hello World". I say:"It works!"
    By Davidovic in forum Member Introductions
    Replies: 4
    Last Post: June 29th, 2010, 07:13 AM
  4. "java.lang.NoSuchMethodError: main" and "fatal exception occured."
    By joachim89 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 10th, 2010, 08:35 AM
  5. Replies: 1
    Last Post: October 25th, 2009, 11:54 AM