Results 1 to 3 of 3

Thread: Ignore Symbol

  1. #1
    Xystus777 is offline Member
    Join Date
    Jan 2009
    Posts
    22
    Rep Power
    0

    Exclamation Ignore Symbol

    Hello everyone,

    Alright, this is my 2nd day programming. I have a program where the user types a double into an input box. I'm telling the user to type a percent. How can I make it, so that if the user types

    "15" OR "15%"

    That they both equal 15?
    In other words, eliminate the "%"?

    Thanks!

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    this:
    Java Code:
    string.replaceAll("\\%", "");
    will return string with all percents removed. i.e.,
    Java Code:
    public class Fubar
    {
      public static void main(String[] args)
      {
        String string1 = "15";
        String string2 = "15%";
        System.out.println(stripPercent(string1));
        System.out.println(stripPercent(string2));
        
        int int1 = Integer.parseInt(stripPercent(string1));
        int int2 = Integer.parseInt(stripPercent(string2));
        
        System.out.println(int1 + int2);
      }
    
      private static String stripPercent(String string)
      {
        return string.replaceAll("\\%", "");
      }
    }

  3. #3
    Xystus777 is offline Member
    Join Date
    Jan 2009
    Posts
    22
    Rep Power
    0

Similar Threads

  1. Replies: 9
    Last Post: 10-18-2008, 08:26 PM
  2. Need a pgeloading symbol
    By jazz2k8 in forum Advanced Java
    Replies: 1
    Last Post: 07-17-2008, 08:56 AM
  3. symbol not found error
    By rmartyce in forum New To Java
    Replies: 1
    Last Post: 05-23-2008, 05:58 AM
  4. Replies: 3
    Last Post: 05-01-2008, 08:30 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
  •