Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

string to array???

Status
Not open for further replies.

AutumnBlues

Programmer
Jul 3, 2002
31
0
0
GB
Any ideas on converting a string to an array?

For example if...

MrString = "Monday, Tuesday, Wednesday"

How do I convert this so that...

MyArray = Array(Monday, Tuesday, Wednesday)

Any help is much appreciated

AutumnBlues
 
Dear Autumnblues

Have a look at the functions Split and Join

regards Astrid
 
Hi,
Try the following function in a module.

Public Function strToArr(ByVal str As String) As Variant
Dim arr() As String
Dim lastPos As Integer
Dim currPos As Integer
Dim i As Integer
lastPos = 1
currPos = 1

If InStr(1, str, &quot;,&quot;, vbBinaryCompare) <> 0 Then
i = -1
Do While InStr(lastPos, str, &quot;,&quot;, vbBinaryCompare) <> 0
currPos = InStr(lastPos, str, &quot;,&quot;, vbBinaryCompare)
ReDim Preserve arr(i + 1)
arr(i + 1) = Mid(str, lastPos, currPos - lastPos)
lastPos = currPos + 1
i = i + 1
Loop
ReDim Preserve arr(i + 1)
arr(i + 1) = Mid(str, lastPos, Len(str) - (lastPos - 1))
Else
ReDim Preserve arr(0)
arr(0) = str
End If
strToArr = arr
End Function Hope it helps. Let me know what happens.
With regards,
PGK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top