--
Given a string [sMessage] with variable amount of fields separated by a delimiter (~), I need to create a String Array [saMessage] so that I can manipulate the fields in an easier form. The string needs to be broken down, then certain sections are checked/updated and I can then re-create the string and send it off (through my Sockets).
But all I need is to figure out how to get the String into String[] format
So for example:
sMessage = Basic~Level 0~192.168.1.100~Index=1~RQ~
(or something like that, we can move/add/remove the ~ delimiter to make it easier to put into the array if required)
I need to convert the string sMessage into the following string[] array
saMessage[] = [Basic, Level 0, 192.168.1.100, Index=1, RQ]
This makes it easier for me to manipulate each section of the string (when in the string array form), that way I can do stuff like saMessage[0] = Advanced, etc ..
Any ideas? (I tried playing with the String and String[] classes and found nothing that could help, do I need to import something?
StringTokenizer st = new StringTokenizer(sMessage, "~");
int tokenCount = st.countTokens();
String[] array = new String[tokenCount];
for (int i = 0; i < tokenCount; i++) {
array[i] = st.nextToken();
}