without using string.length() how to find string length?
4 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   ysmanyam1_subbu
Posted On:   Monday, July 17, 2006 08:01 AM

without using string.length() how to find string length?

Re: without using string.length() how to find string length?

Posted By:   Robert_Lybarger  
Posted On:   Sunday, August 20, 2006 02:37 PM

Is that supposed to be a trick question? Have a look at String's getBytes(). I'll leave the rest up to you.

Re: without using string.length() how to find string length?

Posted By:   Anonymous  
Posted On:   Sunday, August 20, 2006 02:11 PM

without useing string.length() method how to find string length

Re: without using string.length() how to find string length?

Posted By:   WarnerJan_Veldhuis  
Posted On:   Monday, July 17, 2006 05:11 PM


String s = "a very long string";
int a1 = s.toCharArray().length;
int a2 = ((CharSequence)s).length();
//warning: ugliest code ever ahead!
int counter = 0;
int a3 = 0;
try {
while ( s.charAt(counter++)) {
//keep me running
}
}
catch( IndexOutOfBoundException e) {
a3 = counter;
}


Why ask yourself the question: how to drive a car from a to b, without driving the car?? How to eat the sandwich without eating the sandwich?? How to type letters without typing letters?? What's the freaking point anyway? Is your teacher trying to get on your nerves? Is he trying to get you to read the API? What!?!? Just use the methods that are available.

Re: without using string.length() how to find string length?

Posted By:   amit_jain  
Posted On:   Monday, July 17, 2006 09:32 AM

Hi,

Please try with String.lastIndexOf("") it will return you the integer value that should be your String length.
About | Sitemap | Contact