Results 1 to 4 of 4
  1. #1
    rpark712 is offline Member
    Join Date
    Sep 2011
    Posts
    14
    Rep Power
    0

    Default Replacing number characters with blanks

    Is there any way to change the word "race1car" into "racecar"?

    Would this method work?


    Java Code:
    String s = "race1car";
    
    String s2 = "";
    		
    s2 = s.replace("1","");

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,985
    Rep Power
    9

    Default Re: Replacing number characters with blanks

    Quote Originally Posted by rpark712 View Post
    Would this method work?
    What happened when you tried it?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    rpark712 is offline Member
    Join Date
    Sep 2011
    Posts
    14
    Rep Power
    0

    Default Re: Replacing number characters with blanks

    It works. What would I have to do if I wanted to replace all the numbers in a String with a space. Would I have to use a for loop or just individually make a new String type for every number replacement?

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,985
    Rep Power
    9

    Default Re: Replacing number characters with blanks

    Well, what have you tried? Did you check out the String API?

    Java Platform SE 6
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Display number of characters like bar chart
    By Dreaming in forum New To Java
    Replies: 6
    Last Post: 10-17-2011, 06:11 AM
  2. Replacing characters at a certain index
    By Slayer in forum New To Java
    Replies: 2
    Last Post: 03-10-2011, 09:49 PM
  3. Replies: 12
    Last Post: 02-05-2011, 11:24 AM
  4. Searching and replacing characters in a File
    By DBaskov in forum New To Java
    Replies: 3
    Last Post: 01-31-2011, 11:39 PM
  5. replacing characters???
    By manda147 in forum New To Java
    Replies: 2
    Last Post: 11-29-2008, 08:19 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
  •