Split string gives empty elementes

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
 
B

Barry Kelly

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
 
D

Dave Sexton

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top