Results 1 to 8 of 8
- 11-19-2010, 02:53 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 7
- Rep Power
- 0
Split a String with split()--Help
Hi everyone,
I am taking an array from a webpage and I am putting all its html code in a string (k). Now I want to split that string so that I will only have the info in a table (each line in a seperate cell). I want to split it (using </tr> as delimiter) but keep the </tr> and not loose it. How can I do that?
String[] x = k.split("</tr>"); //This line looses the </tr>.
I would also appreciate any other suggestions.
- 11-19-2010, 03:17 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,401
- Blog Entries
- 7
- Rep Power
- 17
- 11-19-2010, 03:27 PM #3
Member
- Join Date
- Nov 2010
- Posts
- 7
- Rep Power
- 0
Well...thanks. Of course this works. But I think there is a way of using split without loosing the delimiter and I can't find and use it properly. It is something like
x.split("(?<=[!])") if the ! is the delimiter, but I can't adjust it into my case.
- 11-19-2010, 03:34 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,401
- Blog Entries
- 7
- Rep Power
- 17
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 11-19-2010, 03:44 PM #5
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
Mhm? That is not a reluctant quantifier or? Thats a special construct and is standing for:
"(?<=X) X, via zero-width positive lookbehind"
Pattern (Java Platform SE 6)
as an example
the output is : [<tr>hello</tr>, <tr>world</tr>] but if </tr> is not the end of the string, the balance after </tr> will find a place in your array too :)Java Code:String k = "<tr>hello</tr><tr>world</tr>"; String[] x = k.split("(?<=</tr>)"); System.out.println(Arrays.toString(x));
can you give an example, how your string looks like and and how you want your array to be filled?
- 11-19-2010, 03:48 PM #6
Member
- Join Date
- Nov 2010
- Posts
- 7
- Rep Power
- 0
- 11-19-2010, 03:49 PM #7
Member
- Join Date
- Nov 2010
- Posts
- 7
- Rep Power
- 0
Oh, and by the way, </tr> is the end of my string so there is no problem. Thanks again
- 11-19-2010, 04:08 PM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,401
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
String split
By soccer_kid_6 in forum New To JavaReplies: 3Last Post: 10-29-2010, 07:51 PM -
String Split
By sarovarc in forum New To JavaReplies: 6Last Post: 04-19-2010, 05:06 AM -
string split
By gisler in forum New To JavaReplies: 6Last Post: 12-17-2009, 02:23 PM -
How to split a String using split function
By Java Tip in forum java.langReplies: 4Last Post: 04-17-2009, 08:27 PM -
How to split a String using split function
By JavaBean in forum Java TipReplies: 0Last Post: 10-04-2007, 09:32 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks