473,748 Members | 6,161 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Delimiter Split

Hello,

The string.Split method is very useful for splitting
strings that use a single character as a delimiter. i.e.:

string str = "First;Second;T hird";

string[] strArray = str.Split(new char[] {';'});

But I am having trouble getting the Split method to split
a string with a delimiter of more than one character.
What is the correct syntax?

string str = "First<;>Second <;>Third";

// This does not work, it gives an "Unhandled Exception
// of type 'System.Executi onEngineExcepti on' in
// mscorlib.dll"
string[] strArray = str.Split(new char[] {'<',';','>'});

Thanks!
Nov 17 '05 #1
2 1433
Hi,

the relationship between chars is OR and not AND.
http://msdn.microsoft.com/library/de.../en-us/cpref/h
tml/frlrfsystemstri ngclasssplittop ic1.asp

Natty Gur, CTO
Dao2Com Ltd.
34th Elkalay st. Raanana
Israel , 43000
Phone Numbers:
Office: +972-(0)9-7740261
Fax: +972-(0)9-7740261
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 17 '05 #2
"Mark Fox" <in**@solelsoft ware.com> wrote in
news:02******** *************** *****@phx.gbl:
Hello,

The string.Split method is very useful for splitting
strings that use a single character as a delimiter. i.e.:

string str = "First;Second;T hird";

string[] strArray = str.Split(new char[] {';'});

But I am having trouble getting the Split method to split
a string with a delimiter of more than one character.
What is the correct syntax?

string str = "First<;>Second <;>Third";

// This does not work, it gives an "Unhandled Exception
// of type 'System.Executi onEngineExcepti on' in
// mscorlib.dll"
string[] strArray = str.Split(new char[] {'<',';','>'});


Mark,

To split on multiple characters, use the Regex.Split method:

using System.Text.Reg ularExpressions ;

...

string str = "First<;>Second <;>Third";
string[] strArray = Regex.Split(str , "<;>");
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 17 '05 #3

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

Similar topics

3
14438
by: Laurent | last post by:
Hello, is it possible to read a file in python line by line by redefining a new end-of-line delimiter ? I would like for example to have the string "END" being the new delimiter for each line. Thanks
2
4355
by: rhungund | last post by:
Hey all... I'm submitting various form variables as arrays, so when I do try to access them when the form is submitted, i do a split on the variable and pop it into an array. for example: aDescriptions = split(request.form("strDescriptions"), ", ") The problem however is if a description contains a comma in the text,
3
19318
by: Hetal Shah | last post by:
It is a C# code. I have a string like, one||two||three I want to split it into one, two and three. string str = "one||two||three"; string myStrs = str.Split("||");
2
2016
by: Elhanan | last post by:
hi all.. i have the following string: 200850625~01~464~^^200850625~01~464~^^200850625~01~908~^^ which i will need to turn to a mutli-dimentional string array i used result.Split(new char{'^','^'}) for the rows but for some reason i get an empty cell between each result, this is also in the documentation, i just don't know why?
16
8252
by: simonc | last post by:
One of the things that drives me mad about vb.net is spending time trying to make a program do something then finding that there's already an inbuild procedure that does exactly the same thing. So before I begin on this can anyone tell me if there is already a routine to do this: I am dividing up a delimited textstring using string.split. The delimiter character is a space, but
4
1145
by: gn | last post by:
I am trying to parse a txt file which looks something like example below: thisemail@email.com thatemail@email.com anotheremail@email.com This is the code I am using: filetoread = file1.Value
2
2697
by: pengb | last post by:
Hello All: A pretty frustrating question to ask! I use the string something = stringx.split (delimiter.tochararray()) mathod to delimit a long string by space! So supposely if the stringx is : " something something1 something2 " I should get string = something, string = something1...etc However question comes what happens if the string looks like this " something something1 something 2" instead of string =...
3
1340
chandru8
by: chandru8 | last post by:
Hi to all My user will upload a excel file in to an access 2003 database, the problem is date format for that i used the split function to split the date from the excel. The problem is in the split function i specified the delimiter as "/" but some user uses "-" at the time iam getting an error subscript out of range If i able to find the system date delimiter ill replace that., thanks in advance.
3
2119
by: gh | last post by:
I have a string that is delimited with commas. Is there a function in C# that will break apart the string at each comma, so I can copy the value to a var? This is a .net v1.1.4 app. TIA
0
8989
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9537
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9367
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9319
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9243
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8241
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4599
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4869
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.