473,378 Members | 1,447 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,378 software developers and data experts.

Multiple Delimiter in a single string! How to count those as one?

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 [0] =
something, string[1] = something1...etc
However question comes what happens if the string looks like this
" something something1 something 2"
instead of string [0] = something, string[1] = something1...

I get string [0] = something string[1] = "" string[2] =
""........string[11] = something1....etc

In excel there is a function in text delimiter to treat all similar
delimiter as one. I just wondering how to do that in C#?

Thank You For your reply!

Oct 19 '06 #1
2 2673
"pengb" <pe******@yahoo.comwrote in news:1161272163.227933.172150
@e3g2000cwe.googlegroups.com:
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 [0] =
something, string[1] = something1...etc
However question comes what happens if the string looks like this
" something something1 something 2"
instead of string [0] = something, string[1] = something1...

I get string [0] = something string[1] = "" string[2] =
""........string[11] = something1....etc

In excel there is a function in text delimiter to treat all similar
delimiter as one. I just wondering how to do that in C#?
You can use RegularExpressions to do this.... pretty simple really:

string s = "something something somethingelse";
string[] ss = System.Text.RegularExpressions.Regex.Split(s, @"\s+");

-mdb
Oct 19 '06 #2
pengb wrote:
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 [0] =
something, string[1] = something1...etc
However question comes what happens if the string looks like this
" something something1 something 2"
instead of string [0] = something, string[1] = something1...

I get string [0] = something string[1] = "" string[2] =
""........string[11] = something1....etc

In excel there is a function in text delimiter to treat all similar
delimiter as one. I just wondering how to do that in C#?
Checking the docs, I see that the string.split method has several
overloads. One of them takes a StringSplitOptions enum:

string[] sa = s.Split(new char[] { ' ' },
StringSplitOptions.RemoveEmptyEntries);

Oct 20 '06 #3

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

Similar topics

4
by: ShyGuy | last post by:
I have a table with 4 fields. Three are used for criteria. I can get the DLookup to work with 1 criteria with the following but can't get it to work with 2 or three. NumofAppts = DLookup("",...
2
by: Mark Fox | last post by:
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;Third"; string strArray = str.Split(new...
9
by: Graham | last post by:
I have been having some fun learning and using the new Controls and methods in .Net 2.0 which will make my life in the future easier and faster. Specifically the new databinding practises and...
16
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. ...
3
by: Craig Buchanan | last post by:
Is there a way to combine these two Replace into a single line? Regex.Replace(Subject, "\&", "&amp;") Regex.Replace(Subject, "\'", "&apos;") Perhaps Regex.Replace(Subject, "{\&|\'}", "{&amp;|&apos;}")...
1
by: TCB | last post by:
How can I separate multiple email addresses entered in a single textbox, the email addresses are separated by (,) or (;) Thanks
33
by: Geometer | last post by:
Hello, and good whatever daytime is at your place.. please can somebody tell me, what the standard behavior of strtok shall be, if it encounters two or more consecutive delimiters like in...
1
by: vang | last post by:
How do I find out which delimiter if found/used when splitting a string with multiple delimiters are defined in a char array? Example: dim i as integer dim returnText as string dim InputText...
4
by: Peted | last post by:
hello, i have a app.config file like so <?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key="rdbUser1Cpu1" value="Cpu1,test"/> </appSettings> </configuration>
12
by: micarl | last post by:
How would i print a report based on criteria selected from several Combo Boxes as well as multiple Multi Select List Boxes, that are located on the same form? I can get one Multi List Box, just...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.