TheAndroDev
TheAndroDev

Reputation: 103

how to ignore continuous space and tab in text in java.

I have problem in getting rid of multiple white space and tabs from a text file while extracting into an array.

Here is what I have done:

arrayofpara = bufdocument.split("[\\r\\n]+\\s");

Let me know what could be wrong with above code?

Thanks!

Upvotes: 1

Views: 664

Answers (1)

stema
stema

Reputation: 93006

What do you want to do exactly?

Now you split on a series of "newline" characters followed by exactly one whitespace character. My guess you want to remove all the following (and preceeding?) whitespace characters. Then you need to add a quantifier to the whitespace character:

Try

 arrayofpara = bufdocument.split("\\s*[\\r\\n]+\\s*");

This will split also on newlines, that are not followed by whitespace characters, because \\s* will match 0 or more whitespaces.

Upvotes: 3

Related Questions