LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default splitting strings

but watch out for strings like:

str = " ITEM 1000 20 X4 "

I would expect overhead using the worksheet function, but I'm betting that
application.trim() will look better when the number of spaces between elements
and the total number of elements gets large.

(No, I didn't test any of that theory!)


RB Smissaert wrote:

It is a Do While loop, but can't see much wrong with it.

Sub test()

Dim str As String
Dim i As Long
Dim arr

str = "ITEM 1000 20 X4"

Do While InStr(1, str, " ", vbBinaryCompare) 0
str = Replace(str, " ", " ", 1, -1, vbBinaryCompare)
Loop

arr = Split(str, " ")

For i = 0 To UBound(arr)
MsgBox arr(i)
Next

End Sub

RBS

"tad_wegner" wrote
in message ...

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
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
find and replace numeric strings in larger text strings Mr Molio Excel Worksheet Functions 8 November 9th 11 05:17 PM
String splitting for inconsistent strings Richard Excel Worksheet Functions 3 June 22nd 06 03:55 AM
Splitting Text strings in one cell Wardy1 Excel Discussion (Misc queries) 1 May 18th 06 01:05 PM
Splitting text strings along commas. Andrew Excel Discussion (Misc queries) 3 January 10th 06 04:01 PM
splitting number strings in excel Bob Excel Worksheet Functions 1 February 3rd 05 03:33 AM


All times are GMT +1. The time now is 03:31 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"