• 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:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

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: 23928
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: 23928
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
 
I've never won anything before. Not even a tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic