Thread: Integer parse

Results 1 to 6 of 6
  1. #1 Integer parse 
    Registered Member
    Join Date
    Jan 2015
    Posts
    277
    Thanks given
    30
    Thanks received
    23
    Rep Power
    34
    So I was wondering how can I parse variables or letters instead of it just being integers...

    Code:
    int z = Integer.parseInt
    Examples would be nice, please.
    Reply With Quote  
     

  2. #2  
    Donator


    Join Date
    Feb 2014
    Age
    26
    Posts
    161
    Thanks given
    261
    Thanks received
    62
    Rep Power
    100
    to parse a string just set the variable to the token. to parse a character just set the variable to the x element of the string where x = the character's position in the string. i don't think there's any static methods you can use to parse whole strings or individual characters
    e.g. in PI's player saving system, the token variable is called 'token2', to set the player's email you'd do something like this
    Code:
                        } else if (line.startsWith("Email")) {
                        	p.Email = token2;
    or if you want only the first character

    Code:
                        } else if (line.startsWith("Email1stchar")) {
                        	p.Email = token2.toCharArray()[0];
    Reply With Quote  
     

  3. Thankful user:


  4. #3  
    Registered Member
    Join Date
    Nov 2009
    Posts
    199
    Thanks given
    66
    Thanks received
    45
    Rep Power
    74
    Code:
    String s = "34";
    int i = Integer.parseInt(s);
    you'll have to surround in try/catch NumberFormatException, but you should be using an IDE so that'll come naturally
    Reply With Quote  
     

  5. Thankful user:


  6. #4  
    Registered Member
    Join Date
    Jan 2015
    Posts
    277
    Thanks given
    30
    Thanks received
    23
    Rep Power
    34
    Quote Originally Posted by Eyeownyew View Post
    Code:
    String s = "34";
    int i = Integer.parseInt(s);
    you'll have to surround in try/catch NumberFormatException, but you should be using an IDE so that'll come naturally
    Appreciate the help guys, and this is what I was looking for, thanks!
    Reply With Quote  
     

  7. #5  
    Donator


    Join Date
    Sep 2007
    Age
    27
    Posts
    2,426
    Thanks given
    125
    Thanks received
    505
    Rep Power
    386
    Quote Originally Posted by Eyeownyew View Post
    Code:
    String s = "34";
    int i = Integer.parseInt(s);
    you'll have to surround in try/catch NumberFormatException, but you should be using an IDE so that'll come naturally
    NumberFormatException is an extension of IllegalArgumentException which extends RuntimeException, so no you don't HAVE to catch or throw it, it will be thrown by default.
    Reply With Quote  
     

  8. Thankful user:


  9. #6  
    Registered Member
    Join Date
    Nov 2009
    Posts
    199
    Thanks given
    66
    Thanks received
    45
    Rep Power
    74
    Quote Originally Posted by donar fabian View Post
    NumberFormatException is an extension of IllegalArgumentException which extends RuntimeException, so no you don't HAVE to catch or throw it, it will be thrown by default.
    Oh interesting. It's still a good idea to if your number is parsed from human input which it.. always is
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. [Shard-1] Action Parser - (Script Parsing)
    By Martin in forum Tutorials
    Replies: 9
    Last Post: 08-05-2010, 10:08 PM
  2. I will pay someone to Integer My server with IPB
    By Michaela in forum Requests
    Replies: 5
    Last Post: 01-11-2009, 11:05 PM
  3. [TuT]Parsed NPC Autospawn loading (317-377)
    By Wolf in forum Tutorials
    Replies: 2
    Last Post: 09-20-2008, 02:31 PM
  4. New random system for integers etc.
    By tj007razor in forum Tutorials
    Replies: 4
    Last Post: 09-13-2008, 09:42 PM
  5. Easy .ini Parsing
    By Daniel in forum Tutorials
    Replies: 2
    Last Post: 09-11-2008, 09:39 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •