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

  • Thread starter Thread starter Elhanan
  • Start date Start date
E

Elhanan

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?
 
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,
 
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/tabh47cf(en-us,vs.80).aspx

Hope this helps
Jay


| 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?
|
 
Back
Top