split with multiple blanks

T

tshad

I am trying to split an address into an array, such that I have a word or
"," in each array element. I also have to account for no blanks between a
word and a comma:

s = "Tustin, CA, 92780"
s.Split(' ')

This would give me:

Tustin,
CA,
92780

Since I want commas in their own element, I replace it with " , " and then
do the split:

strAddress = s.Replace(",", " , ").Split(' ');

This gives me:

Tustin
,

CA
,

92780

There is a null element after both commas. Is there a way to tell it to
split on multiple blanks as one blank or to ignore null elements?

Thanks,

Tom
 
A

Author

tshad said:
I am trying to split an address into an array, such that I have a word or
"," in each array element. I also have to account for no blanks between a
word and a comma:

s = "Tustin, CA, 92780"
s.Split(' ')

This would give me:

Tustin,
CA,
92780

Since I want commas in their own element, I replace it with " , " and then
do the split:

strAddress = s.Replace(",", " , ").Split(' ');

This gives me:

Tustin
,

CA
,

92780

There is a null element after both commas. Is there a way to tell it to
split on multiple blanks as one blank or to ignore null elements?

Thanks,

Tom

Chk out this:

http://msdn.microsoft.com/en-us/library/system.stringsplitoptions.aspx
 

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