|
-
Mar 22nd, 2003, 10:43 PM
#1
Thread Starter
Lively Member
on string length
if a string contains: "Hello" (without the inverted comas),what's the length?
5? or is it 6 (is there a null value or something at the end)?
-
Mar 22nd, 2003, 10:46 PM
#2
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Mar 22nd, 2003, 10:54 PM
#3
Thread Starter
Lively Member
thanks for your replies crptcblade. but i'm still in a rut...
i'm using the string tokenizer to split up a string of characters, using the contents of another string (ID) as the delimiter:
StringTokenizer st = new StringTokenizer(plaintext, ID, true);
therefore, if the string is "HEL®LO", and that "®" is not in the ID string, the return of each token should be:
H
E
L
®L
O
working with each token, i have to ignore characters that are not in the ID string.... thus i'm trying to get the last character in each token (delimiters being the values present in ID).... using:
n = get.length();
convget = get.charAt((n - 1));
no problems in compilation but errors pop up during runtime:
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String ind
ex out of range: 142
at java.lang.String.charAt(Compiled Code)
at Crypt.encrypt(Compiled Code)
at CryptDriver.main(Compiled Code)
arrrggghhhhhhhhhhhhhh!!!!!!!!!!!
-
Mar 23rd, 2003, 01:18 PM
#4
Dazed Member
Using the code below i can't see how you would get a StringIndexOutOf BoundsException unless the String had a length of zero(which you would then get a negative index). Since the error you are getting is a positive value you are trying access an index greater than length - 1.
Code:
public class S{
public static void main(String[] args){
String s = "Hello";
int l = s.length();
char c = s.charAt((l - 1));
System.out.println(c);
}
}
Last edited by Dilenger4; Mar 23rd, 2003 at 01:35 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|