Spliting a string on a second space and not all spaces
Mike Bates
Ranch Hand
Joined: Sep 19, 2009
Posts: 81
posted
0
I have a series of stings that I want to get values for but there are extra spaces that cause extra gyrations I am hoping someone would be able to help me around.
The string has embedded newlines and returns which I split on first to get to the specific lines and now need to get the number on the line and associate it with a variable.
The number is part of the splitting regex and will therefore not show up in the non-matched parts. Take a look at the Javadoc of Pattern for how (positive) lookahead works.
For the hard-coded String it'll work like a charm, unfortunately it won't successfully match line terminators for text files created on Windows, Unix (based) and older Mac OS operating systems. See http://en.wikipedia.org/wiki/Newline.
Mike Bates
Ranch Hand
Joined: Sep 19, 2009
Posts: 81
posted
0
Okay, thanks. I was not worried about OSs. (though I did not say that upfront.) And I did not catch that as an issue or even think about it, which I need to remember.
I am pulling data from a serial device. The coded strings are surrounded by newlines and returns.
Thanks
Mike
Ulrika Tingle
Ranch Hand
Joined: Nov 24, 2009
Posts: 92
posted
0
Mike Bates wrote:Any thoughts?
Sometimes it's easier and faster to do some old-fasioned parsing.