say for example you have a string that has key values but the variables after it can change ex:
KEY1=variable1, KEY2=variable2, KEY3=variable3
What I want to know is what is the best way to extract variable1, variable2, and variable3. It would be nice if I knew the the substrings and got them each time, but I don't bc the variables can change. Note the keys do not change
You can try this:
String str = "KEY1=variable1, KEY2=variable2, KEY3=variable3";
String[] strArr = str.split(",");
String[] strArr2;
for (String string : strArr) {
System.out.println(string); // ---- prints key-value pair
strArr2 = string.trim().split("=");
System.out.println(strArr2[1]); // ---- prints value
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With