That is a nice one, thanks for the tip.
Replace in a Do While loop is about 50% faster though.
RBS
"Dave Peterson" wrote in message
...
VBA has a Trim() function--but it leaves multiple embedded spaces intact.
But you can use application.trim(). That cleans up the leading/trailing
spaces
(just like VBA's Trim()), but it also eliminates those multiple embedded
spaces--just leaving one when it's done:
Option Explicit
Sub testme01()
Dim myStr As String
Dim mySplit As Variant
Dim iCtr As Long
myStr = "ITEM 1000 20 X4"
myStr = Application.Trim(myStr)
mySplit = Split(myStr, " ")
For iCtr = LBound(mySplit) To UBound(mySplit)
MsgBox iCtr & "--" & mySplit(iCtr)
Next iCtr
End Sub
tad_wegner wrote:
I have multiple strings like the following...
"ITEM 1000 20 X4"
I want to split the string into an array. So I did the following...
tmp = split(line)
Now this is the array data...
tmp[0] = "ITEM"
tmp[1] = " "
tmp[2] = " "
tmp[3] = "100"
tmp[4] = " "
..and so on.
I want to get rid of the blank array points; tmp[1], tmp[2], tmp[4]
such that the array will read like this...
tmp[0] = "ITEM"
tmp[1] = "100"
tmp[2] = "20"
..and so on.
Is there a way to split strings on "white space". I only ask because
the strings I will be digesting are of variable length. I can program a
do-while-loop to count the number of blank entries and work around, but
I figured there had to be an easier way to do that.
THANKS TONS
-Todd
--
tad_wegner
------------------------------------------------------------------------
tad_wegner's Profile:
http://www.excelforum.com/member.php...o&userid=27770
View this thread:
http://www.excelforum.com/showthread...hreadid=536619
--
Dave Peterson