Results 1 to 6 of 6
  1. #1
    porchrat is offline Senior Member
    Join Date
    Mar 2009
    Posts
    105
    Rep Power
    0

    Default using String.charAt() for semicolons

    Hi all

    Been a while since I posted here.

    I haven't tested it yet, but thought I should try asking nonetheless. When using the charAt(int) method from the String class what would it return if the character at that index were a semicolon?

    For example if I had the String hell;o

    and used

    Java Code:
    if (stringName.charAt(stringName.length-2) == ';')
    would that work or would I need to use the unicode number (UTF 59 as my research has told me) for a semicolon instead?

    If both work then what are the pros/cons of each approach?

    Perhaps relatively simple for you guys but it something I have been thinking about.

    Thanks in advance for your help everyone.
    Last edited by porchrat; 01-11-2010 at 12:02 PM.

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

    Default

    Quote Originally Posted by porchrat View Post
    I haven't tested it yet, ...
    You know what the correct answer here is: For gosh sake, test it!.

    Come on now. There is no substitute for this.

  3. #3
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    Quote Originally Posted by Fubarable View Post
    You know what the correct answer here is: For gosh sake, test it!.

    Come on now. There is no substitute for this.
    Hey, that code could make his toaster explode. Better yours than his :p
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  4. #4
    porchrat is offline Senior Member
    Join Date
    Mar 2009
    Posts
    105
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    You know what the correct answer here is: For gosh sake, test it!.

    Come on now. There is no substitute for this.
    lol fair enough I need to test it, it is just a large batch run that takes hours to run to completion so that answer is going to take time.

    It isn't so much whether or not it will work as I don't see why it won't work I just wanted to know what the pros and cons were of the two approaches. :p

  5. #5
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    You can create a test case that take small fractions of a second to run.

  6. #6
    porchrat is offline Senior Member
    Join Date
    Mar 2009
    Posts
    105
    Rep Power
    0

    Default

    Quote Originally Posted by r035198x View Post
    You can create a test case that take small fractions of a second to run.
    have ended up doing that, looks good. So it does work (when referring to the semicolon as ';').

    I would still like some insight as to why someone would use the UTF-16/UTF-32 value of 59 instead as I have seen code in which coders do that instead.

    Personally doesn't make sense to me as if at some point the encoding changes the number would no longer correspond to a semicolon or am I wrong?

    Is it perhaps faster that way?

Similar Threads

  1. Replies: 7
    Last Post: 11-03-2009, 02:18 AM
  2. combine string[] into string like perl's join function
    By tekberg in forum Advanced Java
    Replies: 9
    Last Post: 02-23-2009, 01:05 PM
  3. Replies: 5
    Last Post: 01-11-2009, 10:12 AM
  4. Palindrom - method charAt()
    By user in forum New To Java
    Replies: 10
    Last Post: 11-16-2008, 04:37 AM
  5. Help With Input.charAt(LastIndex);
    By susan in forum AWT / Swing
    Replies: 1
    Last Post: 08-07-2007, 04:22 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
  •