Line break behavior

I request data from my server and get a line in the form 2|bit.ly|1||1|and |should be seperator.

I though the following code snippet should do the job

BufferedReader br = null;
...
br = new BufferedReader(new InputStreamReader(inputStream));
...

String line;
String[] columns;
ContentValues values;

while((line = br.readLine())!=null) {
    columns = line.split("|");
    ...
}

but then line.split("|");the columns contain 15 elements instead of the expected. 6. Looking at it, the contents show that each character in the string was stored in one element of the array.

Does anyone have an idea what is wrong with this? The code coming from the server is not encoded in any way in the example in which I use only ASCII characters.

+3
source share
1 answer

String.split , '|' . , . line.split("\\|");

: Java, regex , '|', '|'.

+6

Source: https://habr.com/ru/post/1770425/


All Articles