how to use a carriage return (CR - \r) or a line feed (LF - \n) as a delimiter

edited March 2017 in How To...

I have to split a file (test.txt) consisting of lines separated by a CR or LF or both. The split() function does not accept the \r or \n codes.

String temp[] = loadStrings(selection.getAbsolutePath());
data= (split(temp [0], '\r'));

test.txt
aap noot mies
tuur poes
kat hond

Tagged:

Answers

  • Try splitTokens(). Please check the reference.

    Kf

  • Answer ✓

    Your temp array is already the split data! That's why it's an array.

    Try println()ing temp[0], temp[1], and temp[2] to see what I mean.

Sign In or Register to comment.