I am trying to parse a String into a few variables. The String could contain these 4 tokens: "name, size, age, gender" but they don't all have to be there. Examples of possible Strings.
Example 1. "name:T-rex;"
Example 2. "name:T-rex;size:8;"
Example 3. "name:T-rex;age:4;gender:female"
I tried to do this:
private String name;
private String size;
private String age;
private String gender;
private String parse(String data)
{
String [] parts = data.split(";");
name = parts[0];
size = parts[1];
age = parts[2];
gender = parts[3];
}
But that only works if the String data contains all 4 tokens. How can I solve this problem? I really do need the 4 variables.
parts, split again on:.datathat is missing thesizeor thegender.