Using regular expression "\s+" in VBA

C

CWen07

Hi,

I am having trouble using the RegEx "\s+" in VBA.
I am using it to split a string that contains characters and spaces
such as
" 1 3 12 1 2 3 4 5 "

I am using an array called varText to store each value.

varText = Split (strText, "\s+")

Can anyone help???
 
J

Jonathan West

CWen07 said:
Hi,

I am having trouble using the RegEx "\s+" in VBA.
I am using it to split a string that contains characters and spaces
such as
" 1 3 12 1 2 3 4 5 "

I am using an array called varText to store each value.

varText = Split (strText, "\s+")

Can anyone help???

The VBA Split function is quite different from the Regexp split function,
and does not use wildcards. Look it up in VBA help. If you want to use
regexp from VBA, you need to set a reference to the Regexp DLL in Tools
References in the VBA editor.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
H

Helmut Weber

Sub test00001()
Dim sTmp As String
Dim vartext() As String
sTmp = " 1 3 12 1 2 3 4 5 "
sTmp = Trim(sTmp)
While InStr(sTmp, " ")
sTmp = Replace(sTmp, " ", " ")
Wend
vartext = Split(sTmp, " ")
End Sub

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top