-7

I am a beginner in java, i was wondering if i can find a value in a string.

Lets say that i have a String like this: "Number 5 hurray", and the number 5 could be any number, is there anyway that i can find what is in between the parts of the string '"Number ' and 'hurray"'?

AskNilesh
  • 67,701
  • 16
  • 123
  • 163

1 Answers1

0

You can split your string by space char, and then you will have an array like this ["Number", "5", "hurray"]. So the number you are looking for is always on position 1.

String s = "Number 5 hurray";
String[] array = s.split(" ");
String number = array[1]; // here your number
Ulad
  • 1,083
  • 8
  • 17