| Author |
how to extract two numbers from a string
|
nathan gibson
Ranch Hand
Joined: Sep 16, 2009
Posts: 120
|
|
this is my code.
this is my output
Please enter your 3 numbers (e.g. 123)
234
userNumber234
userInput234
firstNumbers2
lastNumbers3
firstNumberOfInput2
secondNumbersOfInput3
randomNumber802
stringRandomNumber802
firstNumbersOfRandomString8
lastNumbersOfRandomString0
firstNumbersOfRandom8
secondNumbersOfRandom0
how can i make the strings "First Numbers" and "Last Numbers" retain the value of of the 0,1 1,2 values of the input and random?
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16695
|
|
how can i make the strings "First Numbers" and "Last Numbers" retain the value of of the 0,1 1,2 values of the input and random?
substring (0,1) will only fetch you the first character. And substring (1,2) will only fetch you the second character. Is this what you want?
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
nathan gibson
Ranch Hand
Joined: Sep 16, 2009
Posts: 120
|
|
no i want this:
789
first = 78
last = 89
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16695
|
|
nathan gibson wrote:no i want this:
789
first = 78
last = 89
The substring indexes are inclusive for the start, and exclusive for the end -- so you want substring(0,2) and substring(1,3).
Henry
|
 |
nathan gibson
Ranch Hand
Joined: Sep 16, 2009
Posts: 120
|
|
|
thank you very much
|
 |
 |
|
|
subject: how to extract two numbers from a string
|
|
|