0

I have a delimited string and The delimiter is "$%". The fields are in an specific order. For example: John$%Smith$%30$%Los Angeles I need to get the values of this string and store them in the respective property

Customer.firstName(_)
Customer.lastName(_)
Customer.age(_)
Customer.city(_)   

So far I have tried this but I know I am doing it incorrectly:

if(thisString != null){
        if(thisString.endsWith("$%")){
            Customer.firstName(thisString.substring(0,indexOf("$%");
        }
    }
Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
AleAng
  • 71
  • 1
  • 9

1 Answers1

3

Trying using Java's String.split

For example:

//Split string based on "$%"
String[] values = thisString.split(Pattern.quote("$%"));
Customer.firstName() = values[0]; //Set first name equal to first string from the split
//etc
River
  • 8,585
  • 14
  • 54
  • 67