473,504 Members | 13,601 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

string.split only accept char[] separator

Hi,

I have a string that needs to be parsed into the string[]. The separator is
not char[]. It is something like " at ". With current string.Split function,
it doesn't work. Is there any exist functions like "Split" that I can use to
do the job? Any idea of the simpliest way to do the job?

Thanks in advance,
Henry
Jul 21 '05 #1
4 2546
String.Split is designed to be pretty basic. You need to use something like
a regex here. For example, given the string

"one::two::three::four::five::six"

this expression:

\w+[^::]

will give you six matches, each with one number.

There's probably a better way (Regex object have a Split method as well),
but you get the idea.
--
____________________
Klaus H. Probst, MVP
http://www.vbbox.com/

"Henry Chen" <he********@postiive-it.com.au> wrote in message
news:eI**************@TK2MSFTNGP11.phx.gbl...
Hi,

I have a string that needs to be parsed into the string[]. The separator is not char[]. It is something like " at ". With current string.Split function, it doesn't work. Is there any exist functions like "Split" that I can use to do the job? Any idea of the simpliest way to do the job?

Thanks in advance,
Henry

Jul 21 '05 #2
"Henry Chen" <he********@postiive-it.com.au> wrote in
news:eI**************@TK2MSFTNGP11.phx.gbl:
Hi,

I have a string that needs to be parsed into the string[]. The
separator is not char[]. It is something like " at ". With
current string.Split function, it doesn't work. Is there any
exist functions like "Split" that I can use to do the job? Any
idea of the simpliest way to do the job?


Henry,

Use the Regex.Split function (found in the
System.Text.RegularExpressions namespace).

Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Jul 21 '05 #3
See string.ToCharArray(). For performance and simplicity, I'd recommend
string.Split(...) over RegEx.

Scott
I have a string that needs to be parsed into the string[]. The separator is not char[]. It is something like " at ". With current string.Split function, it doesn't work. Is there any exist functions like "Split" that I can use to do the job? Any idea of the simpliest way to do the job?

Jul 21 '05 #4
Henry,
There are three Split functions in .NET:

Use Microsoft.VisualBasic.Strings.Split if you need to split a string based
on a specific word (string). It is the Split function from VB6.

Use System.String.Split if you need to split a string based on a collection
of specific characters. Each individual character is its own delimiter.

Use System.Text.RegularExpressions.RegEx.Split to split based
on matching patterns.

If you are using C#, you can reference the Microsoft.VisualBasic.dll
assembly to use the first function.

Hope this helps
Jay

"Henry Chen" <he********@postiive-it.com.au> wrote in message
news:eI**************@TK2MSFTNGP11.phx.gbl...
Hi,

I have a string that needs to be parsed into the string[]. The separator is not char[]. It is something like " at ". With current string.Split function, it doesn't work. Is there any exist functions like "Split" that I can use to do the job? Any idea of the simpliest way to do the job?

Thanks in advance,
Henry

Jul 21 '05 #5

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

Similar topics

11
2483
by: Carlos Ribeiro | last post by:
Hi all, While writing a small program to help other poster at c.l.py, I found a small inconsistency between the handling of keyword parameters of string.split() and the split() method of...
10
8120
by: Alex | last post by:
I'm looking for a fast way to split a string into individual tokens. The typical format of the string is token1|token2|token3|...|tokenN| and the number of tokens varies (which is why i use a...
3
2298
by: tvn007 | last post by:
Please help, I am not sure why this code not even compile due to line 39 and 44. Thanks in advance for any help 1 #include <cctype> 2 #include <iostream> 3 #include <string> 4 #include...
7
13765
by: Mad Scientist Jr | last post by:
I have been doing this kind of thing in VB and VB.net for a long time, but am having problems in C#: First I want to split up a string by the backslash character, but this line: arrSplit =...
2
31366
by: James | last post by:
Hi, I am looking for a stringtokenizer class/method in C#, but can't find one. The similar classes in Java and C++ are StringTokenizer and CStringT::tokenize respectively. I need to keep a...
9
2617
by: ad | last post by:
I have a string like "1,2,2,3,3,3,4" I want to trim off the duplicate part, and make it to "1,2,3,4" How can I do?
4
316
by: Henry Chen | last post by:
Hi, I have a string that needs to be parsed into the string. The separator is not char. It is something like " at ". With current string.Split function, it doesn't work. Is there any exist...
12
3021
by: John | last post by:
Hi I have a multi-line address field which has each line separated by CRLF. How can I split this field into individual strings using crlf as separator? Thanks Regards
10
5498
by: vunet.us | last post by:
Hello, I use XMLHTTP to get an HTML of another page. Then, I need to cut some middle part of that HTML string but I have problems doing it (see note in caps below). The error I have generated at...
0
7213
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7298
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7366
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5610
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3187
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.