• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

how to extract two numbers from a string

 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no i want this:
789
first = 78
last = 89
 
Henry Wong
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you very much
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic