Problems with string split
I am trying to read and parse the header of a dat file. I am porting code over from C++ where name-value pairs are easily handled by copying the header to a char array and doing sscanf( --, "%s %f",--).
In Java I am reading the file in through a dataInputStream and doing a read(char, 0, 80*Character.SIZE) where 80*Character.SIZE is the length of the header. I then convert the char array to a string, and this is where things get funny.
If I do a println on this string nothing prints out, if I do a trim on this string then the first name-value pair prints. (I am looking at this output in an Eclipse IDE console viewer).
If I do s1 = s1.replace("//W+"," "), everything that is in the header is printed out except values that have negatives or decimal points are split at that point, meaning 67.52 becomes 67 52.
If I do String s2 = s1.split("//W+") it does the same as above and will place non-integer numbers in two separate elements.
If I do String s2 = s1.split("[ ]+"), all the values are kept in good condition but all the names are removed.
I can look at this file in emacs and see there are '@' between each name-value pair and whitespace between the actual name and value.
Hopefully I have provided enough information. Please let me know if you can help out in any way.
Thanks in advance.