I have a string of around a hundred lines, it is unknown whether the lines will be "\r\n" or "\n".
I want to parse the string once, processing each line.
This question almost answers mine, but there's no mention of how to deal with unknown new line delimiting characters.
I was thinking of using one of the above methods, choosing "\n" as the delimiter and then stripping any "\r" characters on a line-by-line basis.
While performance really isn't an issue, I'd like to know if there is a cleaner way of doing this. I have not been able to find any methods that automatically handle line delimiter types.
Attempt #1, as per suggestion from @TritonMan:
Scanner scanner = new Scanner(myString);
String line = scanner.nextLine();
// line contains whole contents of string, not just the first line
If it matters, I am running this on Android. The string comes from a PLS file (playlist) which doesn't seem to be well defined anywhere, so I do not know what type of line delimiters it uses.
As a fallback, I will use the code from this question, but it's now bugging me how to do it without regex or String.split()
in case I deal with streams:
String lines[] = String.split("\\r?\\n");