By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,997 Members | 1,470 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,997 IT Pros & Developers. It's quick & easy.

why does split function leaves empty cells in more the one delimiter?

P: n/a
hi all..

i have the following string:
200850625~01~464~^^200850625~01~464~^^200850625~01 ~908~^^

which i will need to turn to a mutli-dimentional string array

i used result.Split(new char[]{'^','^'}) for the rows
but for some reason i get an empty cell between each result, this is
also in the documentation, i just don't know why?

Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi,

It does perfectly sense, The interpretation of the separators is of a OR ,
not a AND , it means that you are saying split by '^' or '^' it see two
together and it interprete it as an empty string ( or an empty field )

Can you in any way get rid of the double ^^ and replace them by a single
one?

ITOH it does not matter in the end, you just check for an empty string and
continue if so:

string[] parts1 = result.Split(new char[]{'^','^'}) ;
foreach( string s in parts1)
if ( s.Length>0 )
{
string[] parts2 = s.Split( new char[] {'~'} );
//do the work
}
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Elhanan" <em*****@hotmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
hi all..

i have the following string:
200850625~01~464~^^200850625~01~464~^^200850625~01 ~908~^^

which i will need to turn to a mutli-dimentional string array

i used result.Split(new char[]{'^','^'}) for the rows
but for some reason i get an empty cell between each result, this is
also in the documentation, i just don't know why?

Nov 17 '05 #2

P: n/a
Elhanan,
In addition to the other comments on Split, there are three Split functions
in .NET:

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

Use System.Text.RegularExpressions.RegEx.Split to split based
on matching patterns.
NOTE: VS.NET 2005 (.NET 2.0) adds an overload to String.Split for String
delimiters:

http://msdn2.microsoft.com/library/t...us,vs.80).aspx

Hope this helps
Jay
"Elhanan" <em*****@hotmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
| hi all..
|
| i have the following string:
| 200850625~01~464~^^200850625~01~464~^^200850625~01 ~908~^^
|
| which i will need to turn to a mutli-dimentional string array
|
| i used result.Split(new char[]{'^','^'}) for the rows
| but for some reason i get an empty cell between each result, this is
| also in the documentation, i just don't know why?
|
Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.