Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default String separated with commas

I have a string looking like:

aaa, bbb, ccc, ddd, eee.....

I want to load an array with these elements - like:

Array(aaa,bbb,ccc,ddd,eee.........).

The elements is separated with comma and space in string.

What is the best way to do this?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default String separated with commas

Sub dural()
s = "a, b, c, d, e"
s2 = Split(Replace(s, " ", ""), ",")
End Sub

Here s2 is an array. s2(0) will contain "a", etc.
--
Gary''s Student - gsnu200770


"Jarle" wrote:

I have a string looking like:

aaa, bbb, ccc, ddd, eee.....

I want to load an array with these elements - like:

Array(aaa,bbb,ccc,ddd,eee.........).

The elements is separated with comma and space in string.

What is the best way to do this?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default String separated with commas

Fantastic - even more elegant that could ever imagine.
Thank you!

Gary''s Student skrev:

Sub dural()
s = "a, b, c, d, e"
s2 = Split(Replace(s, " ", ""), ",")
End Sub

Here s2 is an array. s2(0) will contain "a", etc.
--
Gary''s Student - gsnu200770


"Jarle" wrote:

I have a string looking like:

aaa, bbb, ccc, ddd, eee.....

I want to load an array with these elements - like:

Array(aaa,bbb,ccc,ddd,eee.........).

The elements is separated with comma and space in string.

What is the best way to do this?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default String separated with commas

You are very welcome. Split is nice because it creates an array without a DIM.


Join() is the opposite.
--
Gary''s Student - gsnu200770


"Jarle" wrote:

Fantastic - even more elegant that could ever imagine.
Thank you!

Gary''s Student skrev:

Sub dural()
s = "a, b, c, d, e"
s2 = Split(Replace(s, " ", ""), ",")
End Sub

Here s2 is an array. s2(0) will contain "a", etc.
--
Gary''s Student - gsnu200770


"Jarle" wrote:

I have a string looking like:

aaa, bbb, ccc, ddd, eee.....

I want to load an array with these elements - like:

Array(aaa,bbb,ccc,ddd,eee.........).

The elements is separated with comma and space in string.

What is the best way to do this?

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default String separated with commas

Sub dural()
s = "a, b, c, d, e"
s2 = Split(Replace(s, " ", ""), ",")
End Sub


You do not have to use the replace function to pare down the delimiter to a
single character like that... the delimiter can contain multiple
characters...

s2 = Split(s, ", ")

where the characters between the quote marks are a comma followed by a
space. Now, with that said, doing what you posted will protect against a
improperly formed string of text where the number of spaces following the
comma are not consistent throughout the text.

Rick



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default String separated with commas

Hi Rick:

Thanks for the tip about being able to use more than one character as a
separator.
--
Gary''s Student - gsnu200770


"Rick Rothstein (MVP - VB)" wrote:

Sub dural()
s = "a, b, c, d, e"
s2 = Split(Replace(s, " ", ""), ",")
End Sub


You do not have to use the replace function to pare down the delimiter to a
single character like that... the delimiter can contain multiple
characters...

s2 = Split(s, ", ")

where the characters between the quote marks are a comma followed by a
space. Now, with that said, doing what you posted will protect against a
improperly formed string of text where the number of spaces following the
comma are not consistent throughout the text.

Rick


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sort data separated by commas dab Excel Worksheet Functions 4 May 14th 10 12:53 AM
How do I de-concatenate items separated by commas! Taneli Hanhivaara Excel Discussion (Misc queries) 2 December 15th 08 11:45 AM
Help! I need a formula to add numbers separated by commas within SUPER EA Excel Worksheet Functions 8 July 27th 07 06:24 PM
Save .csv file. Decimals separated by commas belitre Excel Programming 2 May 10th 04 11:36 AM
parsing words in a cell separated by commas spjoseph0511[_4_] Excel Programming 2 December 16th 03 09:19 PM


All times are GMT +1. The time now is 02:11 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"