android - Java regex help needed to split string please! How to ignore an empty line? -


I am a complete noob for regex and I need help in dividing the string I am inputting the following data < / P> 635 11% R1908 388 FG Root Top 61 1% S 42 152404 of 29716 FG System System Server 38 0% S 1 840 340 FG Route / System / bin / Qumd 114 0% s 16 120160 FG radio com.android.phone

19156 which is nothing but your regular top output

  655 11% R1 FG Root Summary S  

The code I now use to do is I

  while ((inputLine = in.readline ()) = null) {String [] segs = inputLine.split ("[] +"); Str [i] = segs [0] + "" [1] + + "[2] +" "+ [2] +" "+ Segments [3] +" + + Segus [6] + "+ + Segus [ 7] + "" + Segus [8]; Logs. V ("top output", str [i]); I ++; J ++; }  

But the problem I am experiencing is that I am on logcat

  java.lang.ArrayIndexOutOfBoundsException  

> Where am I going, and what can I do to stop it? Thanks for helping.

EDIT: After reading the comments, I know that there are some empty lines in my output. In such cases how should I ignore the line I know that I want to match any case I am, but I am not sure about expression or syntax!

You do not need a character class (square brackets). Space Regeks has a regular character, therefore:

  string [] segs = inputLine.split ("+");  

In addition, assuming array index is bad style for checking without limits and an ArrayIndexOutOfBoundsException is the one you have asked for.

Better explain this:

  string again = "^ \\ s * (\\ S +) \\ s + (\\ S +) \\ S + (\\ s +) \\ s + (\\ s +) \\ s + (\\ s +) \\ s + (\\ s +) \\ s + (\\ s +) \ s + (\\ s +) \\ s + (\\ + S) \\ s * $ "; Pattern p = Pattern.compile (again, pattern. MULTILINE); Matcher m = p.matcher (yourInputString); This is guaranteed in such a way through (m.find ()) {// do m.group with goods (1) m.group (9)}  

That what you meet your expectations and what you expect in each maternity group.

Disclaimer: I am not particularly proud of that reggae. It is quite ugly, in fact, but it clarifies that it has been estimated from clear and more reliable and approximate. And it has the ability to improve a version that can match the string split more accurately than the desired parts.


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -