I am having trouble at finding a way to iterate through a string of alphabets until a digit is reached.

e.g. iterating through

//Using a scanner, I can use scanner.getNext() to get the first word. 
//There may be more than one word; there is no way to tell; the algorithm must figure it out.

String iCanDo= "Seoul 235 253";   //One word. I can read this through scanner.getNext();
String canNotDo = "Anyong Haseyo 142.153 535353";   //2 words; I can't do this.

I suppose the main question is: How do I iterate through the string until a digit appears?

Thank you!
(...and if you are wondering, I am learning Korean. :) )

6 Years
Discussion Span
Last Post by NormR1

Use the string method charAt(int index) in a loop to get the chars one at a time. The Char class then has methods to tell you if a char is a letter or a number or whatever.


If there are more then one word, y dont u use InputdialogBox or textfield?

there MAY be more than one word.


iterate through a string of alphabets until a digit is reached.

Have you tried using the charAt() method that James suggested?

The presence of "words" in a String will not be a problem with the charAt method.
By words I assume you mean letters delimited by whitespace or punctuation.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.