How to find integer in String

Hi ,I have a problem to find the integer in a string like "1234hi"String str="123hi";i should not use any iterators.i want to convert it withou looping.can any one help me on this.Regards,Bhaskar.
[245 byte] By [newjava1234a] at [2007-11-27 5:47:16]
# 1
Given the conditions, java.util.regex sounds like the solution.
robtafta at 2007-7-12 15:31:30 > top of Java-index,Java Essentials,Java Programming...
# 2

take a look as the isDigit method in the Character class.

Character.isDigit(str.charAt(index))

if you do this in a loop and then break out when you hit a non-digit. You can then substring based on a count you incremented in the loop.

EDIT: I need glasses. No loops

Message was edited by:

_helloWorld_

_helloWorld_a at 2007-7-12 15:31:30 > top of Java-index,Java Essentials,Java Programming...
# 3

> take a look as the isDigit method in the Character

> class.

>

> > Character.isDigit(str.charAt(index))

>

>

> if you do this in a loop and then break out when you

> hit a non-digit. You can then substring based on a

> count you incremented in the loop.

>

> EDIT: I need glasses. No loops

>

> Message was edited by:

> _helloWorld_

His homework assignment explicitly disallows looping

georgemca at 2007-7-12 15:31:30 > top of Java-index,Java Essentials,Java Programming...
# 4
With these conditionsit's easiest to use java.text.NumberFormat.import java.text.*;...fmt=NumberFormat.getInstance();print(fmt.parse("1234hi")); // 1234
jsalonena at 2007-7-12 15:31:30 > top of Java-index,Java Essentials,Java Programming...
# 5

> With these conditionsit's easiest to use

> java.text.NumberFormat.import java.text.*;

> ...

> fmt=NumberFormat.getInstance();

> print(fmt.parse("1234hi")); // 1234

^^I never thought of that, I did think of this however.

public class Example {

static int index;

public static void main(String[] args) {

System.out.println(getNumbers("123xx"));

}

static String getNumbers(String s ) {

if(Character.isDigit(s.charAt(index))) {

index++;

getNumbers(s);

}

return s.substring(0, index);

}

}

_helloWorld_a at 2007-7-12 15:31:30 > top of Java-index,Java Essentials,Java Programming...
# 6
The regex "(?<=\\d)(?!\\d)|(?<=\\D)(?=\\d)" will split a String every time a boundary between digits and non-digits is encountered. The resulting tokens with either be numeric or non numeric which is easy enough to test.
YoGeea at 2007-7-12 15:31:30 > top of Java-index,Java Essentials,Java Programming...
# 7

Hi,

without iterator, i don't think it is possible.

try this one

String str="123hi";

String val="";

for(int i=0;i<str.length();i++)

{

if(Character.isDigit(str.charAt(i)))

val=val+str.charAt(i);

}

thn convert this string into integer.>

RAMJANEa at 2007-7-12 15:31:30 > top of Java-index,Java Essentials,Java Programming...
# 8
I am guessing that recursion is the answer to what your professor is looking for, but it looks like you got 3 different solutions to your question!
robtafta at 2007-7-12 15:31:30 > top of Java-index,Java Essentials,Java Programming...