string - java : search for a word in a text and give its line -
I have string output (a paragraph) that has approximately 140 lines, I want to find a word in this paragraph for example I have a line in the paragraph for:
Date: 08/12/2009 Value: 58 9.236 Smooth smth fax: 25896217 I search terms The value of this gives me line 2 in the paragraph, in fact I use this code to get the number of lines:
string result = "..." mater = m = pattern.compile ("(\ n) | (\ r) | (\ r \ n)") matching (result). Int lines = 1; While (m.find ()) {lines ++; } Is there a predefined method in Java that gives me a line of similar words?
As far as I know, there is no one, then my solution is to split text into lines and The text line must be scanned from the line, unless the word is found. Then return a line number. Public class zero main (string [] ARG) {string text = "Date: 08/12/2009" + "\ n" + "Value: 589.236" + "
\ N "+" smth: smth "+" \ n "+" fax: 25896217 "; System.out.println ("'smth' found in the first row:" + FindFirstOccurenceLineNumber (text, "smth")); } Private static int for first-octoberline number (string text, string needle) {string lines [] = text. Split ("\ r | \ n | \ r \ n | \ n \ r", -1); Int Lincoln = 1; (Line line: lines) (if line canteen (needle)) {return line number;} line number ++;} return -1;}}
Comments
Post a Comment