Re: Similar to SPLIT

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Yes, it works now.
Interesting and neat, but about twice as slow as with Mid or a Byte array. Setting a reference to RegExp makes it a bit faster, but not much.
Thanks in any case for the tip.

RBS

"Dana DeLouis" <ddelouis@xxxxxxxxxxxxx> wrote in message news:eDuoK5G%23GHA.4468@xxxxxxxxxxxxxxxxxxxxxxx
It leaves out spaces though and I can't turn in into a function.

Thanks for the feedback. This may not be the best approach, as I'm not sure what the op had in mind as a function.
We can make a small change to include spaces as below.
Here are a couple of general ideas. Both test examples print the first and last character.
However, in the second example, the line "Set RE =" is skipped, thus saving a little setup time.
Other speed-ups would be to set a vba library reference, and avoid the CreateObject line.
Again, just some general ideas.

Option Explicit
Public RE As Object

Function RE_Split(s As String) As Variant
If RE Is Nothing Then
Set RE = CreateObject("VBScript.RegExp")
RE.Global = True
'// Any word character or white space character
RE.Pattern = "\w|\s"
End If

If RE.Test(s) Then
Set RE_Split = RE.Execute(s)
End If
End Function

Sub TestIt()
Dim v As Variant
Set v = RE_Split("12 ab")
Debug.Print v(0)
Debug.Print v(4)

Set v = RE_Split("ab xyz")
Debug.Print v(0)
Debug.Print v(v.Count - 1)
End Sub


--
HTH :>)
Dana DeLouis
Windows XP & Office 2003


"RB Smissaert" <bartsmissaert@xxxxxxxxxxxxxxxx> wrote in message news:u22LEWF%23GHA.3392@xxxxxxxxxxxxxxxxxxxxxxx
That's an interesting one.
It leaves out spaces though and I can't turn in into a function.

RBS

"Dana DeLouis" <ddelouis@xxxxxxxxxxxxx> wrote in message news:eRVY5PF%23GHA.4712@xxxxxxxxxxxxxxxxxxxxxxx
>...zero-based one dimensional array?

Just to mention another option.
A Regular Expression is zero based also.

Sub Demo()
Dim RE As Object
Dim M As Variant
Dim s As String
Dim J As Long

Set RE = CreateObject("VBScript.RegExp")
s = "abcdef"

RE.Global = True
RE.Pattern = "\w"
Set M = RE.Execute(s)

'// Zero based...
For J = 0 To M.Count - 1
Debug.Print M(J)
Next J
End Sub

--
HTH :>)
Dana DeLouis
Windows XP & Office 2003


"Gary''s Student" <GarysStudent@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:81030A9C-FAB9-499D-8B91-3252E8420AF4@xxxxxxxxxxxxxxxx
Does VBA supply a builtin function like SPLIT() that returns an array
containing the individual characters in a string, or would one have to be
coded?
--
Gary's Student






.



Relevant Pages

  • RXParse module v.91 (by robic0)
    ... # Unicode character reference ... sub original_content ... then call content handler with $content ...
    (comp.lang.perl.misc)
  • Re: Dynamic References to Word?
    ... Sub ListExcelReferences() ... Dim i As Long ... First set the reference manually in the VBE under Tools, ... On Error GoTo ERROROUT ...
    (microsoft.public.excel.programming)
  • Re: Dynamic References to Word?
    ... Sub ListExcelReferences() ... Dim i As Long ... .ColorIndex = xlAutomatic ... First set the reference manually in the VBE under Tools, ...
    (microsoft.public.excel.programming)
  • Re: Before Double Click
    ... Yes, but in the routine where you pass the object reference, you when you ... Dim rngVal As Range ... Sub EFG(ByVal r1 As Range, ByRef r2 As Range) ...
    (microsoft.public.excel.programming)
  • Re: Auto Load Add-In
    ... you posted that will unload the addin. ... Sub ListAddins() ... Dim adn As AddIn ... I also assume the reason you want to add a project reference to the addin to ...
    (microsoft.public.excel.programming)