473,836 Members | 2,123 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

String.Split needs an enhancement to ignore empty fields

We need an additional function in the String class. We need the ability
to suppress empty fields, so that we can more effectively parse. Right
now, multiple whitespace characters create multiple empty strings in the
resulting string array.
Nov 16 '05 #1
19 10929
If String.Split doesn't fit your needs you have to create your own split
method which isn't very complicated. String.Split is designed that it meets
the most common application needs.

--
cody

Freeware Tools, Games and Humour
http://www.deutronium.de.vu || http://www.deutronium.tk
"David Logan" <dj******@comca st.net> schrieb im Newsbeitrag
news:dtTDc.1666 70$3x.58747@att bi_s54...
We need an additional function in the String class. We need the ability
to suppress empty fields, so that we can more effectively parse. Right
now, multiple whitespace characters create multiple empty strings in the
resulting string array.

Nov 16 '05 #2
cody wrote:
If String.Split doesn't fit your needs you have to create your own split
method which isn't very complicated. String.Split is designed that it meets
the most common application needs.

--
cody

Freeware Tools, Games and Humour
http://www.deutronium.de.vu || http://www.deutronium.tk
"David Logan" <dj******@comca st.net> schrieb im Newsbeitrag
news:dtTDc.1666 70$3x.58747@att bi_s54...
We need an additional function in the String class. We need the ability
to suppress empty fields, so that we can more effectively parse. Right
now, multiple whitespace characters create multiple empty strings in the
resulting string array.


Which is what I have done. But parsing strings of data with multiple
whitespace characters between fields *is* a very common operation. So I
am disagreeing with the part about "meeting the most common application
needs."

Anyway, I just sent it out in case somebody thought "oh, yea, that would
be a good idea."

David Logan
Nov 16 '05 #3
Have you considered using regular expressions (REGEX) to split the string? I have used it to accomplish what you describe.

See System.Text.Reg ularExpressions

"David Logan" wrote:
We need an additional function in the String class. We need the ability
to suppress empty fields, so that we can more effectively parse. Right
now, multiple whitespace characters create multiple empty strings in the
resulting string array.

Nov 16 '05 #4
Yes, I have considered it, but I prefer not to use a very expensive
regex for an otherwise simple split. String.Split is perfect save the
fact that in something like:
"abc def ghi jkl mnop"

I get an array of 80 elements instead of 5.
I prefer to save regex for parsing strings when:

1) You don't know what you're going to get next
(in a loop of string processing), or
2) There are various optional pieces in a string
that may or may not occur.

In these instances, simple splitting and checking results is already
pretty expensive, so using regex isn't a stretch.

David Logan

Bill O'Neill wrote:
Have you considered using regular expressions (REGEX) to split the string? I have used it to accomplish what you describe.

See System.Text.Reg ularExpressions

"David Logan" wrote:

We need an additional function in the String class. We need the ability
to suppress empty fields, so that we can more effectively parse. Right
now, multiple whitespace characters create multiple empty strings in the
resulting string array.

Nov 16 '05 #5
> >>We need an additional function in the String class. We need the ability
to suppress empty fields, so that we can more effectively parse. Right
now, multiple whitespace characters create multiple empty strings in the
resulting string array.


Which is what I have done. But parsing strings of data with multiple
whitespace characters between fields *is* a very common operation. So I
am disagreeing with the part about "meeting the most common application
needs."

Anyway, I just sent it out in case somebody thought "oh, yea, that would
be a good idea."


In that case RegEx.Split(str ing delim) is your friend.
Use @"\s" as separator in your case (IIRC).

--
cody

Freeware Tools, Games and Humour
http://www.deutronium.de.vu || http://www.deutronium.tk
Nov 16 '05 #6
I have to agree with David on this one. Every time I looked at StringSplit
to do simple splitting I gave up on it because of all the extra empty
strings.

Philippe

"David Logan" <dj******@comca st.net> wrote in message
news:rpVDc.1295 76$Sw.70819@att bi_s51...
Yes, I have considered it, but I prefer not to use a very expensive
regex for an otherwise simple split. String.Split is perfect save the
fact that in something like:
"abc def ghi jkl mnop"

I get an array of 80 elements instead of 5.
I prefer to save regex for parsing strings when:

1) You don't know what you're going to get next
(in a loop of string processing), or
2) There are various optional pieces in a string
that may or may not occur.

In these instances, simple splitting and checking results is already
pretty expensive, so using regex isn't a stretch.

David Logan

Bill O'Neill wrote:
Have you considered using regular expressions (REGEX) to split the string? I have used it to accomplish what you describe.
See System.Text.Reg ularExpressions

"David Logan" wrote:

We need an additional function in the String class. We need the ability
to suppress empty fields, so that we can more effectively parse. Right
now, multiple whitespace characters create multiple empty strings in the
resulting string array.

Nov 16 '05 #7
David,
In addition to the other comments.

There are three Split functions in .NET:

Use Microsoft.Visua lBasic.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.S plit if you need to split a string based on a collection
of specific characters. Each individual character is its own delimiter.

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

In your example I would use RegEx.Split, unless it was proven via profiling
to be a performance problem in the routine you are using (remember the 80-20
rule).

Hope this helps
Jay
"David Logan" <dj******@comca st.net> wrote in message
news:dtTDc.1666 70$3x.58747@att bi_s54...
We need an additional function in the String class. We need the ability
to suppress empty fields, so that we can more effectively parse. Right
now, multiple whitespace characters create multiple empty strings in the
resulting string array.

Nov 16 '05 #8
I was unaware of the .VisualBasic. namespace routines.

Performance may or may not be a problem depending upon which packets I
would need to parse in this manner. I just try to avoid regex in general
unless I need its flexibility.

What is the "80/20" rule?

David Logan

Jay B. Harlow [MVP - Outlook] wrote:
David,
In addition to the other comments.

There are three Split functions in .NET:

Use Microsoft.Visua lBasic.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.S plit if you need to split a string based on a collection
of specific characters. Each individual character is its own delimiter.

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

In your example I would use RegEx.Split, unless it was proven via profiling
to be a performance problem in the routine you are using (remember the 80-20
rule).

Hope this helps
Jay
"David Logan" <dj******@comca st.net> wrote in message
news:dtTDc.1666 70$3x.58747@att bi_s54...
We need an additional function in the String class. We need the ability
to suppress empty fields, so that we can more effectively parse. Right
now, multiple whitespace characters create multiple empty strings in the
resulting string array.


Nov 16 '05 #9
David,
Performance may or may not be a problem depending upon which packets I
would need to parse in this manner. I just try to avoid regex in general
unless I need its flexibility. Generally if I am going to be reusing the same RegEx, I apply the
RegexOptions.Co mpiled option and keep the RegEx itself in a static member.
What is the "80/20" rule? I've heard various variations of it, basically 80% of the time is spent in
20% of the code.

Basically I write "correct" code first, rather then worry how well it will
perform, I only go back & optimize routines, once those routines have proven
to be a performance problem... By "correct" I primarily mean OOP, plus using
the tools available, such as RegEx to solve a problem, if those tools fit
the requirement. Of course "correct" is subjective.

Hope this helps
Jay
"David Logan" <dj******@comca st.net> wrote in message
news:yG4Ec.1694 67$3x.99527@att bi_s54... I was unaware of the .VisualBasic. namespace routines.

Performance may or may not be a problem depending upon which packets I
would need to parse in this manner. I just try to avoid regex in general
unless I need its flexibility.

What is the "80/20" rule?

David Logan

Jay B. Harlow [MVP - Outlook] wrote:
David,
In addition to the other comments.

There are three Split functions in .NET:

Use Microsoft.Visua lBasic.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.S plit if you need to split a string based on a collection of specific characters. Each individual character is its own delimiter.

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

In your example I would use RegEx.Split, unless it was proven via profiling to be a performance problem in the routine you are using (remember the 80-20 rule).

Hope this helps
Jay
"David Logan" <dj******@comca st.net> wrote in message
news:dtTDc.1666 70$3x.58747@att bi_s54...
We need an additional function in the String class. We need the ability
to suppress empty fields, so that we can more effectively parse. Right
now, multiple whitespace characters create multiple empty strings in the
resulting string array.


Nov 16 '05 #10

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

Similar topics

4
728
by: William Stacey [MVP] | last post by:
Would like help with a (I think) a common regex split example. Thanks for your example in advance. Cheers! Source Data Example: one "two three" four Optional, but would also like to ignore pairs of brackets like: "one" <tab> "two three" ( four "five six" ) Want fields like:
3
6037
by: Rico | last post by:
If there are consecutive occurrences of characters from the given delimiter, String.Split() and Regex.Split() produce an empty string as the token that's between such consecutive occurrences. It sounds like making sense, but has anyone ever found this useful? Can this 'feature' be disabled? After having used StringTokenizer from the J-language that's not to be named, it's annoyed me for hours before I figured out that it was just a...
2
8575
by: Dan Schumm | last post by:
I'm relatively new to regular expressions and was looking for some help on a problem that I need to solve. Basically, given an HTML string, I need to highlight certain words within the text of the string. I had it working somewhat, but ran into problems if one of the highlighted words could also be part of an HTML tag (such as 'Table' or 'Border'). What I need is the regex to find the word, but ignore any words that fall between an HTML...
20
5669
by: Guadala Harry | last post by:
In an ASCX, I have a Literal control into which I inject a at runtime. litInjectedContent.Text = dataClass.GetHTMLSnippetFromDB(someID); This works great as long as the contains just client-side HTML, CSS, etc. What I want to do is somehow insert a *server control* into the , then set the server control's properties at runtime.
5
5882
by: kurt sune | last post by:
The code: Dim aLine As String = "cat" & vbNewLine & "dog" & vbNewLine & "fox" & vbNewLine Dim csvColumns1 As String() = aLine.Split(vbNewLine, vbCr, vbLf) Dim csvColumns2 As String() = Microsoft.VisualBasic.Strings.Split(aLine, vbNewLine, -1, CompareMethod.Binary)
4
6055
by: Michele Petrazzo | last post by:
Hello ng, I don't understand why split (string split) doesn't work with the same method if I can't pass values or if I pass a whitespace value: >>> "".split() >>> "".split(" ") But into the doc I see:
10
2745
by: klineb | last post by:
Good Day, I have written and utility to convert our DOS COBOL data files to a SQL Server database. Part of the process requires parsing each line into a sql statement and validting the data to keep the integrity of the database. We are parsing roughl 81 files and range in size 1 kb to 65 MB files (Average of 400,000 lines in the larger files). I have written this utility with VB.NET 2003 and when I parse all of the files I run out...
3
3270
by: 6afraidbecause789 | last post by:
If able, can someone please help make a Where clause that strings together IDs in a multi-select listbox AND includes a date range. I wasn’t thinking when I used the code below that strings together the IDs of Clients from a multi-select listbox in an unbound text field, txtCriteria, on a form that is used to pick different reports. It appears that I now have so many clients that I’ve reached the 255 character limit in the txtCriteria...
14
1738
by: Stevo | last post by:
If you split a string into an array using the split method, it's not working the way I'd expect it to. That doesn't mean it's wrong of course, but would anyone else agree it's working somewhat illogically? Here's a test I just put together that splits on "&". The test strings are: "a&b" = (Correct!) I expect array length 2 and I get 2 "a&" = (Incorrect!) I expect array length 1 but I get 2 "a" = (Correct!) I expect array length 1 and...
0
9812
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
9657
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10823
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
10532
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
10577
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
9359
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
6975
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();...
1
4443
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3103
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.