How to join up 1 demensional array into 1 string?

onesegun
onesegun used Ask the Experts™
on
Hi Experts,

I have an array called RowArray(ia) with ia being 1 to 59 which has stored values in them. Now what I want to do is concatenate all RowArrays from 1 to 59 in a single string without writing 'Variable = RowArray(1)&","&RowArray(2)&","&RowArray(3)' etc. all the way to RowArray(59).

Can anyone tell me how to do this efficiently perhaps in some kind of loop?

Thanks,

OS
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Try this:
Dim x as integer
for x = 1 to 59
    Variable = variable & rowarray(x)
Next

Open in new window

Commented:
Or if you want commas...

(I put a space after the comma in the quotes - you can leave it out if you want)
Dim x as integer
for x = 1 to 59
    Variable = variable & rowarray(x) & ", "
Next

Open in new window

Without a loop:
s = Join(RowArray)

Open in new window

CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

Since you want commas
s = Join(RowArray, ",")

Open in new window

Commented:
Nice!

Author

Commented:
Nice work guys! Both solutions were excellent though understandably I went for the simplest which was using the Join method.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial