473,398 Members | 2,368 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,398 software developers and data experts.

Handling nulls in tab-delimited string?

Apparently, the Split method handles consecutive tabs as a single delimiter. Does anyone have any suggestions for handling consecutive tabs?

I am reading in text files that contain lines of tab-delimited data. I was using string[] stringArray = lineOfText.Split('\t') to automatically populate an array used to populate the values in a new DataRow.

However, sometimes the lines of text contain null values. I can find these null values by opening the file in a text editor and using the arrow keys locate consecutive Tabs with, presumably, a null value between them.

Any help is greatly appreciated.

- VS
Nov 16 '05 #1
4 6827
Vagabond Software <carlfenley-X-@-X-san.rr.com> wrote:
Apparently, the Split method handles consecutive tabs as a single
delimiter.


String.Split doesn't. For instance:

using System;

public class Test
{
static void Main()
{
string x ="a\t\tb";
string[] values = x.Split();
foreach (string value in values)
{
Console.WriteLine(value);
}
}
}

prints "a" then a blank line (the empty value) then "b".

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message news:MP************************@msnews.microsoft.c om...
Vagabond Software <carlfenley-X-@-X-san.rr.com> wrote:
Apparently, the Split method handles consecutive tabs as a single
delimiter.


String.Split doesn't. For instance:

using System;

public class Test
{
static void Main()
{
string x ="a\t\tb";
string[] values = x.Split();
foreach (string value in values)
{
Console.WriteLine(value);
}
}
}

prints "a" then a blank line (the empty value) then "b".


Thanks for the reply. I discovered late last night that it was I who was mishandling the consecutive tabs and not the Split method.

- VS
Nov 16 '05 #3
As you've already discovered, Split() does work correctly for the situation
you mentioned; however one thing it doesn't work correctly for is
quote-delimited strings containing the field delimiter itself. For example,
in a comma-delimited file:

Joe,Schumuck,"123 Maple St, Apt 4",Anytown,CA,90000

Would be mis-parsed as Split() is not designed to recognize a delimiter
within a quoted string as not being a delimiter.

You would have to write your own routine to handle situations like that.

I mention this in case quoted strings are possible in your input.

--Bob

"Vagabond Software" <carlfenley-X-@-X-san.rr.com> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...
Apparently, the Split method handles consecutive tabs as a single delimiter.
Does anyone have any suggestions for handling consecutive tabs?

I am reading in text files that contain lines of tab-delimited data. I was
using string[] stringArray = lineOfText.Split('\t') to automatically
populate an array used to populate the values in a new DataRow.

However, sometimes the lines of text contain null values. I can find these
null values by opening the file in a text editor and using the arrow keys
locate consecutive Tabs with, presumably, a null value between them.

Any help is greatly appreciated.

- VS
Nov 16 '05 #4
"Bob Grommes" <bo*@bobgrommes.com> wrote in message news:Od**************@TK2MSFTNGP10.phx.gbl...
As you've already discovered, Split() does work correctly for the situation
you mentioned; however one thing it doesn't work correctly for is
quote-delimited strings containing the field delimiter itself. For example,
in a comma-delimited file:

Joe,Schumuck,"123 Maple St, Apt 4",Anytown,CA,90000

Would be mis-parsed as Split() is not designed to recognize a delimiter
within a quoted string as not being a delimiter.

You would have to write your own routine to handle situations like that.

I mention this in case quoted strings are possible in your input.


I certainly appreciate the tip. Though I have not run into quoted data yet, there are literally thousands of the client's files I have not yet run through my parser. There's no telling what I might find.

- VS
Nov 16 '05 #5

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

Similar topics

3
by: Thomas Coleman | last post by:
I have been playing around with 2.0 and I'm trying clarify a few things about generics and data access. I was hoping to be able to do something like this with nullable types: int? foo = null; ...
2
by: ezelasky | last post by:
We are using the bcp utility (via APIs) to export data from a SQL table in a fixed format text file. BCP is inserting spaces for a field if the field contains a NULL. This is fine with us except...
1
by: spshealy | last post by:
Greetings, I have a question about how nulls are handled in "IN" clauses.. I understand the operation null = anyvalue is undefined. Please examine the following example. drop table one...
4
by: pw | last post by:
Hi, I have month names (coming from a field in a table) as the column heading in an Access 97 crosstab query. It is being sorted alphabetically. This will not do. The only way that I know to...
14
by: tshad | last post by:
I have people telling me that I should set up objects for my tables, but I am finding the Null problem makes that difficult. It isn't a big problem if you are not updating the table, but if you...
6
by: Michal Hlavac | last post by:
hello, I have interesting problem... I have stored procedure, which works good, but only if input is "correct". Correct input is, when $1 is id, which exists in table... If I put non exists id,...
2
by: Jan Smith | last post by:
I have a C# project with tab control with eight tab pages. I would like to allow the text or the text color to change when an event occurs, then have the text or text color change back when the...
5
by: AAJ | last post by:
Hi Does anyone know of any good publically available set of standards for managing dates when dealing with a database server (in my case SQL Server 2000 and c# VS2005). At the moment, if I...
17
by: Kbalz | last post by:
I'm developing a Wizard type program, and I'm flipping between steps by using a TabControl.. buttons on each tabPage move to the next or previous tabPage. When I press CTRL+Tab however, the...
0
by: csauer | last post by:
I am writing a program using visual basic.NET 2003 to be used to update and store data in a database I have stored in Access 2003. I am using a OdbcDataAdapter to generate my dataset, then using a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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...
0
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
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...
0
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
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
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,...

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.