473,222 Members | 1,802 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,222 software developers and data experts.

splitting string with a string

I have a html page that I retrived and stored in a string and I want
to split it based on <tdelements. I know only way you can split
using string.split is using characters. The other option is traverse
and split. Is there any other way you can split a string using string
token itself?
Thanks,
Jul 30 '08 #1
10 1348
On Jul 30, 3:24*pm, CSharper <cshar...@gmx.comwrote:
I have a html page that I retrived and stored in a string and I want
to split it based on <tdelements. I know only way you can split
using string.split is using characters. The other option is traverse
and split. Is there any other way you can split a string using string
token itself?
Use Regex.Split.

Jon
Jul 30 '08 #2
On Jul 30, 6:24*pm, CSharper <cshar...@gmx.comwrote:
I have a html page that I retrived and stored in a string and I want
to split it based on <tdelements. I know only way you can split
using string.split is using characters. The other option is traverse
and split. Is there any other way you can split a string using string
token itself?
Yes; use String.Split. It has an overload which takes String (not
char) delimiters:

public string[] Split(
string[] separator,
StringSplitOptions options
)

Jul 30 '08 #3
CSharper,

Have you taken a look at the RegEx class? Specifically, the Split
method on the RegEx class?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"CSharper" <cs******@gmx.comwrote in message
news:57**********************************@r66g2000 hsg.googlegroups.com...
>I have a html page that I retrived and stored in a string and I want
to split it based on <tdelements. I know only way you can split
using string.split is using characters. The other option is traverse
and split. Is there any other way you can split a string using string
token itself?
Thanks,

Jul 30 '08 #4
On Jul 30, 9:27*am, "Jon Skeet [C# MVP]" <sk...@pobox.comwrote:
On Jul 30, 3:24*pm, CSharper <cshar...@gmx.comwrote:
I have a html page that I retrived and stored in a string and I want
to split it based on <tdelements. I know only way you can split
using string.split is using characters. The other option is traverse
and split. Is there any other way you can split a string using string
token itself?

Use Regex.Split.

Jon
Duh???

Thanks.
Jul 30 '08 #5
CSharper wrote:
I have a html page that I retrived and stored in a string and I want
to split it based on <tdelements. I know only way you can split
using string.split is using characters. The other option is traverse
and split. Is there any other way you can split a string using string
token itself?
Thanks,
As suggested, the Regex class also has a Split method, but you can do
better than that with a regular expression.

You can use the pattern "<td[^>]*>([\w\W]*?)</td>" with the Regex.Match
method to find the contents of all td elements in the string.

<td[^>]*matches the starting tag even if it has arguments
[^>] matches any character except >
* means zero or more matches
() catches the value
[\w\W] matches any character
*? makes a non-gready match, so that it ends at the first </td>, not the
last

Note: This doesn't work well if you have nested tables.

--
Göran Andersson
_____
http://www.guffa.com
Jul 30 '08 #6
On Jul 30, 3:55*pm, CSharper <cshar...@gmx.comwrote:
Use Regex.Split.

Duh???
Which part didn't you understand? In the RegEx class, there's a Split
method. Construct an appropriate regex, and call the Split method.

As Pavel mentioned, String also now contains an overload for
String.Split which takes an array of delimiter strings instead of
chars. It's "new" to 2.0, but hopefully that won't be an issue for
you.

Jon

Jul 30 '08 #7
haha, he was talking about himself I believe. As in "Duh, why didn't I
figure that out"
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:5b**********************************@s50g2000 hsb.googlegroups.com...
On Jul 30, 3:55 pm, CSharper <cshar...@gmx.comwrote:
Use Regex.Split.

Duh???
Which part didn't you understand? In the RegEx class, there's a Split
method. Construct an appropriate regex, and call the Split method.

As Pavel mentioned, String also now contains an overload for
String.Split which takes an array of delimiter strings instead of
chars. It's "new" to 2.0, but hopefully that won't be an issue for
you.

Jon
Jul 30 '08 #8
Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard.caspershouse.comwrote:
haha, he was talking about himself I believe. As in "Duh, why didn't I
figure that out"
Ah, that would explain it :)

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Jul 30 '08 #9
I actually used this functionality quite heavily recently, to narrow in on
an encoded url in a webpage source. I split the string after a "<td
id=\"...\">" element, or something similar, that occurred once and was
unique, and took the second part.
Then I took the first part of the split at "</td>".
Then I took the second part of "<a href=\"".
Then I took the first part of ">".

"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:5b**********************************@s50g2000 hsb.googlegroups.com...
On Jul 30, 3:55 pm, CSharper <cshar...@gmx.comwrote:
Use Regex.Split.

Duh???
Which part didn't you understand? In the RegEx class, there's a Split
method. Construct an appropriate regex, and call the Split method.

As Pavel mentioned, String also now contains an overload for
String.Split which takes an array of delimiter strings instead of
chars. It's "new" to 2.0, but hopefully that won't be an issue for
you.

Jon
Jul 30 '08 #10
They may be using .NET 1.1, which doesn't have the string parameter
overloads.

"Pavel Minaev" <in****@gmail.comwrote in message
news:c9**********************************@34g2000h sf.googlegroups.com...
On Jul 30, 6:24 pm, CSharper <cshar...@gmx.comwrote:
I have a html page that I retrived and stored in a string and I want
to split it based on <tdelements. I know only way you can split
using string.split is using characters. The other option is traverse
and split. Is there any other way you can split a string using string
token itself?
Yes; use String.Split. It has an overload which takes String (not
char) delimiters:

public string[] Split(
string[] separator,
StringSplitOptions options
)
Jul 30 '08 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: qwweeeit | last post by:
Splitting with RE has (for me!) misterious behaviour! I want to get the words from this string: s= 'This+(that)= a.string!!!' in a list like that considering "a.string" as a word. Python...
5
by: fatted | last post by:
I'm trying to write a function which splits a string (possibly multiple times) on a particular character and returns the strings which has been split. What I have below is kind of (oh dear!)...
4
by: JeffM | last post by:
Quick C# question: I have comma delimited values in a string array that I want to pass to seperate variables. Any tips on splitting the array? Thanks in advance! JM
2
by: Trint Smith | last post by:
Ok, My program has been formating .txt files for input into sql server and ran into a problem...the .txt is an export from an accounting package and is only supposed to contain comas (,) between...
20
by: Opettaja | last post by:
I am new to c# and I am currently trying to make a program to retrieve Battlefield 2 game stats from the gamespy servers. I have got it so I can retrieve the data but I do not know how to cut up...
2
by: CharChabil | last post by:
Using Vb.net 2005, I want to read each part in this string in an array (splitting the string) ----------- A1/EXT "BK82 LB73 21233" 105 061018 1804 ----------- That Code that i used is as follow:...
6
by: HMS Surprise | last post by:
The string s below has single and double qoutes in it. For testing I surrounded it with triple single quotes. I want to split off the portion before the first \, but my split that works with...
2
by: shadow_ | last post by:
Hi i m new at C and trying to write a parser and a string class. Basicly program will read data from file and splits it into lines then lines to words. i used strtok function for splitting data to...
4
by: yogi_bear_79 | last post by:
I have a simple string (i.e. February 27, 2008) that I need to split into three parts. The month, day, and year. Splitting into a string array would work, and I could convert day and years to...
37
by: xyz | last post by:
I have a string 16:23:18.659343 131.188.37.230.22 131.188.37.59.1398 tcp 168 for example lets say for the above string 16:23:18.659343 -- time 131.188.37.230 -- srcaddress 22 ...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.