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.Spli t('\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 4 6857
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.WriteLi ne(value);
}
}
}
prints "a" then a blank line (the empty value) then "b".
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message news:MP******** *************** *@msnews.micros oft.com... 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.WriteLi ne(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
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,"1 23 Maple St, Apt 4",Anytown,CA,9 0000
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******** *******@TK2MSFT NGP11.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.Spli t('\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
"Bob Grommes" <bo*@bobgrommes .com> wrote in message news:Od******** ******@TK2MSFTN GP10.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,"1 23 Maple St, Apt 4",Anytown,CA,9 0000 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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;
DataRow dr = ...;
dr = foo;
However, this does not work if the DataType value is set to int. In that
|
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 at the end of
the line, there are no spaces for that field just the end-of-row
terminator prematurely, so it looks like that field is not present and
messes up another piece of software we pump the text file into down
stream.
Example -- The...
|
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
DB20000I The SQL command completed successfully.
create table one( first char(3), next1 int) in mcd_fl_coord3
|
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 get
around it is to use month numbers instead, but I'd rather have the
names appear.
Any ideas?
|
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 are -
it is a real problem if you have Nullable fields. You can't always use a 0
or -1 to tell whether a field is null and dates are another problem. I
don't want to use some obscure date in the future for something like
"EndDate" or...
| |
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, database fall down and restart with this error:
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.
|
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 tab is clicked. However, I don't
find a click event handler specifically for the individual tab pages. I can
change the tab page text on an unrelated event, but I don't see a handler to
allow it to be changed back when the tab is clicked. Any...
|
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 create a record in the database for say a job, the
invoicedOn date field will be left null within the data base, not being
assigned untill its actually invoiced.
|
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 tabControl begins to cycle through
the tabPages, just as it does in Visual Studio, IE7 etc.. any tabbed
program.
I need this blocked.
|
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 form as my data entry.
Every time I go to add a new record to my dataset to save to my Table, I receive this error message... 'An unhandled exception has occurred in your application ... Column "FP" does not allow nulls.'
Now FP is a column in...
|
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...
| |
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,...
|
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...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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();...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |