Hi,
I know you said you think you have the solution but I thought I would post this to demonstrate one method of doing it for anyone who is curious. The idea is that you could just split the string as normal using the Split function and use the Len function to get the length of each portion, adding one to this would give the position that the string was split at.
I.e. if the first portion of the string is 8 characters long then it would have been split at position 9, if the second portion of the string is 4 characters long then it would have been split at position 14. Len(first string) = 8 + 1 + Len(second string) = 4 + 1
The whole thing would look something like this:
Code:
Dim original_string As String 'The original string to be split
Dim splitarray() As String 'Array to hold the portions of the string
Dim posarray() As String 'Array to hold the split positions
Dim runningtotal As Integer 'Variable to keep a count of the positions
Dim a As Integer 'Counter for Loop
Private Sub Command1_Click()
runningtotal = 0
'String to split
original_string = "this-is-a-string"
'Split the string and store the portions in an array
splitarray = Split(original_string, "-")
ReDim posarray(1)
For a = 0 To UBound(splitarray)
If a > 1 Then ReDim Preserve posarray(UBound(posarray) + 1)
'Add position of split to the running total
'Position of split is equal to the length of the current
'array element plus 1
runningtotal = runningtotal + Len(splitarray(a)) + 1
posarray(a) = runningtotal
Next
End Sub
The positions of the splits will now be stored in an array called posarray which should have the same subscript positions as the strings to which they refer. Note, the last position of the posarray will contain the position of the end of the string so can be disregarded. By swapping two lines
over so that you write the runningtotal to the posarray before you calculate the split position:
Code:
posarray(a) = runningtotal
runningtotal = runningtotal + Len(splitarray(a)) + 1
The first position of your posarray will now contain zero, the second element will contain the position of the first split etc. which may be better!!
This is probably the same logic that you used, if not then I would be interested to see how you accomplished it!!