Author
Returning lenght of a string
Raymond Owens
Greenhorn
Joined: Jun 16, 2009
Posts: 7
How do I take a given string and return the number of characters that the string has?
For example, "character" is made up of 9 individual characters. What line of code will examine a string and answer this for me?
David Newton
Author
Rancher
Joined: Sep 29, 2008
Posts: 12617
posted Jun 19, 2009 18:01:55
0
Have you looked at the java.lang.String JavaDocs ?
Raymond Owens
Greenhorn
Joined: Jun 16, 2009
Posts: 7
codePointCount?
David Newton
Author
Rancher
Joined: Sep 29, 2008
Posts: 12617
posted Jun 19, 2009 18:34:09
0
Length.
Raymond Owens
Greenhorn
Joined: Jun 16, 2009
Posts: 7
I had already tried length (apparently in the wrong context) and couldn't make it work. When trying to use the less than operator, I get the error that this cannot be used with java.lang.string, int.
David Newton
Author
Rancher
Joined: Sep 29, 2008
Posts: 12617
posted Jun 19, 2009 19:12:44
0
Without seeing any code it's hard to know where you went wrong. For example, the following works fine:
subject: Returning lenght of a string