how to get string variables from a whole string in java.
if i am given a string which is created this way:
String s = "Name:" + name + "Age:" + age + "Sex:" + sex;
how can i get name, age, sex from this String s.
I cannot use getWord(position) or something like that because i dont know how many words will be there in name, and how the age is represented
age = “22 years” or age = “22 years 5 months”.
I suggest you to have the
Name,AgeandSexsplitted by","character.It means:
Then you can split the string s by “,”
Then from properties variable, you can split by
":"to take the Property name and the value of that property.Is that clear?
I’m adding more code to support another ways as you wanted:
Please be note that this is just example show you the logic, you need to refactor yourself.