Results 1 to 6 of 6
- 01-11-2010, 11:54 AM #1
Senior Member
- Join Date
- Mar 2009
- Posts
- 105
- Rep Power
- 0
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
would that work or would I need to use the unicode number (UTF 59 as my research has told me) for a semicolon instead?Java Code:if (stringName.charAt(stringName.length-2) == ';')
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.
-
- 01-11-2010, 12:06 PM #3
- 01-11-2010, 12:20 PM #4
Senior Member
- Join Date
- Mar 2009
- Posts
- 105
- Rep Power
- 0
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
- 01-11-2010, 12:27 PM #5
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
You can create a test case that take small fractions of a second to run.
- 01-11-2010, 01:40 PM #6
Senior Member
- Join Date
- Mar 2009
- Posts
- 105
- Rep Power
- 0
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
-
The constructor Person(String, String, Date) is undefined
By fh84 in forum New To JavaReplies: 7Last Post: 11-03-2009, 02:18 AM -
combine string[] into string like perl's join function
By tekberg in forum Advanced JavaReplies: 9Last Post: 02-23-2009, 01:05 PM -
Let eclipse warn about a semicolon after an if statement and string == string?
By foobar.fighter in forum EclipseReplies: 5Last Post: 01-11-2009, 10:12 AM -
Palindrom - method charAt()
By user in forum New To JavaReplies: 10Last Post: 11-16-2008, 04:37 AM -
Help With Input.charAt(LastIndex);
By susan in forum AWT / SwingReplies: 1Last Post: 08-07-2007, 04:22 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks