• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to extract two numbers from a string  RSS feed

 
nathan gibson
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
nathan gibson
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no i want this:
789
first = 78
last = 89
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you very much
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!