I'm trying to pull "part numbers" within a given paragraph(string) and
place them in an array. Part numbers format is "xxx-xxxx". What's the
best way to scan through the paragraph and send all found part numbers
to an array? Thanks in advance guys!
Would this be the best(fastest) way to do this?

SUB getParts(aryParts,sText,nCount)
DO WHILE INSTR(sText,"-") <> 0 '*LOOP THROUGH ENTIRE sText UNTIL NO
MORE '-' REMAIN
tText = RIGHT(sText,LEN(sText)-INSTR(sText,"-")+3) '*FORMAT tText TO
FIRST POSSiBLE MATCH
IF MID(tText,9,1) = " " THEN '*IF POSSIBLE MATCH FITS THEN CONTINUE
aryParts(nCount) = TRIM(LEFT(tText,8)) '*ADD FOUND PART NUMBER TO
ARRAY
nCount=nCount+1 '*CONTINUE COUNT OF TOTAL FOUND PARTS
END IF
sText = RIGHT(sText,LEN(sText)-INSTR(sText,"-")-1) '*SETUP sText FOR
NEXT RUN
LOOP
END SUB


~Greg

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Re: Howto Search Text only knowing part of the word by Viatcheslav

Viatcheslav
Fri Apr 30 13:39:05 CDT 2004

Why not use regular expressions? You will need just to set pattern and you
will get matches collection. Look help for RegExp object.

Function RegExpTest(patrn, strng)
Dim regEx, Match, Matches ' Create variable.
Set regEx = New RegExp ' Create a regular expression.
regEx.Pattern = patrn ' Set pattern.
regEx.IgnoreCase = True ' Set case insensitivity.
regEx.Global = True ' Set global applicability.
Set Matches = regEx.Execute(strng) ' Execute search.
For Each Match in Matches ' Iterate Matches collection.
RetStr = RetStr & "Match found at position "
RetStr = RetStr & Match.FirstIndex & ". Match Value is '"
RetStr = RetStr & Match.Value & "'." & vbCRLF
Next
RegExpTest = RetStr
End Function
WScript.Echo RegExpTest("\d{3}-\d{4}", "some text 123-4567 other text
987-6543 another text")

I supposed all X in xxx-xxxx are numbers.

//------------------------------------
Regards,
Vassiliev V. V.
http://www-sharp.com -
Scripting/HTA/.Net Framework IDE

"Greg Taylor" <gregory_taylor@dell.com> ???????/???????? ? ????????
?????????: news:uqdEeZsLEHA.2244@tk2msftngp13.phx.gbl...
> I'm trying to pull "part numbers" within a given paragraph(string) and
> place them in an array. Part numbers format is "xxx-xxxx". What's the
> best way to scan through the paragraph and send all found part numbers
> to an array? Thanks in advance guys!
> Would this be the best(fastest) way to do this?
>
> SUB getParts(aryParts,sText,nCount)
> DO WHILE INSTR(sText,"-") <> 0 '*LOOP THROUGH ENTIRE sText UNTIL NO
> MORE '-' REMAIN
> tText = RIGHT(sText,LEN(sText)-INSTR(sText,"-")+3) '*FORMAT tText TO
> FIRST POSSiBLE MATCH
> IF MID(tText,9,1) = " " THEN '*IF POSSIBLE MATCH FITS THEN CONTINUE
> aryParts(nCount) = TRIM(LEFT(tText,8)) '*ADD FOUND PART NUMBER TO
> ARRAY
> nCount=nCount+1 '*CONTINUE COUNT OF TOTAL FOUND PARTS
> END IF
> sText = RIGHT(sText,LEN(sText)-INSTR(sText,"-")-1) '*SETUP sText FOR
> NEXT RUN
> LOOP
> END SUB
>
>
> ~Greg
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!