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

Splitting with multiple spaces

I have a text file that appears to be delimited by multiple spaces. The
split function will only work with one space if I am correct. Is there some
way to split this file into an array without getting the extra spaces?
Nov 16 '05 #1
5 22913
Hi Christine!

if understood you're needs correctly, i suggest you to use
System.Text.Regex's Split() function instead of the String's one. It
supports a String parameter.

--
Best Regards
Yanick
"Christine" <Ch*******@discussions.microsoft.com> a écrit dans le message de
news:9B**********************************@microsof t.com...
I have a text file that appears to be delimited by multiple spaces. The
split function will only work with one space if I am correct. Is there some way to split this file into an array without getting the extra spaces?

Nov 16 '05 #2
On Tue, 21 Dec 2004 12:07:02 -0800, Christine wrote:
I have a text file that appears to be delimited by multiple spaces. The
split function will only work with one space if I am correct. Is there some
way to split this file into an array without getting the extra spaces?


Use the Regex (System.Text.RegularExpressions.Regex) split instead as it
allows pattern matching rather than single character or specific string
matching.

Regex r = new Regex(" +");
string [] splitString = r.Split(stringWithMultipleSpaces);
--
Tom Porterfield
Nov 16 '05 #3
Okay that helps with the spaces, but now I have a problem of a carriage
return at the end of each line that Regex doesn't take care of. Is there
some way to take care of this as well as the multiple spaces? Thanks so much
for the help!

"Tom Porterfield" wrote:
On Tue, 21 Dec 2004 12:07:02 -0800, Christine wrote:
I have a text file that appears to be delimited by multiple spaces. The
split function will only work with one space if I am correct. Is there some
way to split this file into an array without getting the extra spaces?


Use the Regex (System.Text.RegularExpressions.Regex) split instead as it
allows pattern matching rather than single character or specific string
matching.

Regex r = new Regex(" +");
string [] splitString = r.Split(stringWithMultipleSpaces);
--
Tom Porterfield

Nov 16 '05 #4
On Wed, 22 Dec 2004 06:45:05 -0800, Christine wrote:
Okay that helps with the spaces, but now I have a problem of a carriage
return at the end of each line that Regex doesn't take care of. Is there
some way to take care of this as well as the multiple spaces? Thanks so much
for the help!


You have several options. You could use the System.String.Replace method
to replace the carriage return with an empty string, or you could use
System.String.TrimEnd - Ex:

string newString =
stringWithCarriageReturn.TrimEnd(new char[]{'\r','\n',' '});

Note that the above will also trim any trailing spaces.
--
Tom Porterfield
Nov 16 '05 #5
Thank you so much, that was very helpful!

"Tom Porterfield" wrote:
On Wed, 22 Dec 2004 06:45:05 -0800, Christine wrote:
Okay that helps with the spaces, but now I have a problem of a carriage
return at the end of each line that Regex doesn't take care of. Is there
some way to take care of this as well as the multiple spaces? Thanks so much
for the help!


You have several options. You could use the System.String.Replace method
to replace the carriage return with an empty string, or you could use
System.String.TrimEnd - Ex:

string newString =
stringWithCarriageReturn.TrimEnd(new char[]{'\r','\n',' '});

Note that the above will also trim any trailing spaces.
--
Tom Porterfield

Nov 16 '05 #6

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

Similar topics

9
by: amitavabardhan | last post by:
How Can I extract multiple tiff images into single images through asp programming? Is there any free dll's that I can use in ASP to split multiple tiffs into single tiffs? Any suggestion...
7
by: Mindy Geac | last post by:
Is it possible to delete special caracters from a string and multiple spaces? When the input is : "a&*bbb cc/c d!d" I want the result : "abbb ccc dd" thnx. MJ <?php
1
by: Anonieko Ramos | last post by:
> > > How to display multiple spaces in a dropdownlist webform1.aspx <asp:DropDownList id="DropDownList1" runat="server"></asp:DropDownList>
1
by: Vikram | last post by:
I have a label control whose text is having multile spaces "Name :" but when this is rendered as html in an aspx page it only shows single space. How to render with multiple spaces.
8
by: Joe Cool | last post by:
I need to map several columns of data from one database to another where the data contains multiple spaces (once occurance of a variable number or spaces) that I need to replace with a single...
4
by: cyberdrugs | last post by:
Hi guys 'n gals, I have a string which contains multiple spaces, and I would like to convert the multiple spaces into single spaces. Example Input: the quick brown fox jumps ...
5
by: polturgiest | last post by:
hie all i got a form <form name="TEST" method=POST action="test.php"> <input type="text" name="MyInput"> <input type="submit" name="ACTION" value="SAVE">
1
by: chris f | last post by:
I'm dynamically populating a Table control in ASP.NET 2. Each row has 4 columns but column #3 needs to be split into 3 rows and column #4 needs to be split into 4 rows. Each of these cells contains...
3
by: bstjean | last post by:
Hi everyone, I am trying to find an efficient way to perform a special query. Let me explain what I want. Let's say we are looking for all description that match "this is the target". In...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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
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...

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.