Split string gives empty elementes

  • Thread starter Thread starter md
  • Start date Start date
M

md

Hi

I am trying to use the Split function to remove characters like ' ',
'=' and ';' from a string, but the problem is that if two delimiters
are next to each other, an empty element is inserted in the result
array. I can not use StringSplitOptions as I use .net 1.

Do you know, how can I get rid of these empty elemets?
Or do you have any hint for using regular expression in this case? And
how this regular expression shall look like?

Thanks very much in advance.

Regards
MD
 
md said:
I am trying to use the Split function to remove characters like ' ',
'=' and ';' from a string, but the problem is that if two delimiters
are next to each other, an empty element is inserted in the result
array. I can not use StringSplitOptions as I use .net 1.

Do you know, how can I get rid of these empty elemets?

Skip over them when iterating the array, or create a new array and only
copy across the non-empty elements.

-- Barry
 
Hi,

Why are you using Split to remove characters?

Unless you require an array containing each delimited string, try using the
Replace method instead with string.Empty as the replacement.
 
Back
Top