English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

For instance:
Blk 216 Dover Road #04-56

2007-06-11 02:18:02 · 3 answers · asked by CD 1 in Computers & Internet Programming & Design

3 answers

First, you need to isolate the number in the string.

string s = "Blk 216 Dover Road #04-56";
string number = s.substring(4,6);

Then you can parse an int from it

int i = Integer.parseInt(number);

Look here for the documentation for the String class:
http://java.sun.com/j2se/1.3/docs/api/java/lang/String.html

There are some indexOf() methods you could use to search the original string if the number isn't always going to be in the same place.

2007-06-11 02:23:54 · answer #1 · answered by mblaine 5 · 0 0

First assign a substring of a string that contains numbers to a string.
Then use parseInt, parseLong, parseFloat or parseDouble to extract the number from the string.

Easy.

2007-06-11 09:26:51 · answer #2 · answered by AnalProgrammer 7 · 0 0

Another example:
http://javablogx.blogspot.com/2014/02/how-to-extract-all-numbers-from-string.html

It uses regular expression with a pattern matcher.

2014-02-16 14:27:51 · answer #3 · answered by JavaCodex 4 · 0 0

fedest.com, questions and answers