|
Post by bplus on Oct 18, 2022 10:02:56 GMT
For best resuts use the BBCode tab found here Sample of the very handy Split Sub and it's complement Join ' note: I buggered this twice now, FOR base 1 array REDIM MyArray (1 to 1) AS ... the (1 to 1) is not same as (1) which was the Blunder!!! 'notes: REDIM the array(0) to be loaded before calling Split '<<<< IMPORTANT dynamic array and empty, can use any lbound though 'This SUB will take a given N delimited string, and delimiter$ and create an array of N+1 strings using the LBOUND of the given dynamic array to load. 'notes: the loadMeArray() needs to be dynamic string array and will not change the LBOUND of the array it is given. rev 2019-08-27 Sub Split (SplitMeString As String, delim As String, loadMeArray() As String) Dim curpos As Long, arrpos As Long, LD As Long, dpos As Long 'fix use the Lbound the array already has curpos = 1: arrpos = LBound(loadMeArray): LD = Len(delim) dpos = InStr(curpos, SplitMeString, delim) Do Until dpos = 0 loadMeArray(arrpos) = Mid$(SplitMeString, curpos, dpos - curpos) arrpos = arrpos + 1 If arrpos > UBound(loadMeArray) Then ReDim _Preserve loadMeArray(LBound(loadMeArray) To UBound(loadMeArray) + 1000) As String curpos = dpos + LD dpos = InStr(curpos, SplitMeString, delim) Loop loadMeArray(arrpos) = Mid$(SplitMeString, curpos) ReDim _Preserve loadMeArray(LBound(loadMeArray) To arrpos) As String 'get the ubound correct End Sub
Function Join$ (arr() As String, delimiter$) Dim i As Long, b$ For i = LBound(arr) To UBound(arr) If i = LBound(arr) Then b$ = arr(LBound(arr)) Else b$ = b$ + delimiter$ + arr(i) Next Join$ = b$ End Function The BBCode Tab avoids the code getting double spaced
|
|