Solved

Multi Split

Posted on 2004-09-04
4
161 Views
Last Modified: 2008-03-06
i want make function SplitDelimiter

Syntax : SplitDelimter(strText,strDelimiter) reture with array

example a = SplitDelimter("hello you:can you?me"," :?")
reture array like this

a(0) = "hello"
a(1) = "you"
a(2) = "can"
a(3) = "you"
a(4) = "me"

how can i do this function can anyone give me the source code.

please dont use For i = 1 to Len(strText) ... Next i
because it make function slow.

thanks you.
0
Comment
Question by:InVisal
  • 3
4 Comments
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
If you are using VB6 it has this built in already.  Its called the Split function.
0
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
If using VB5 or previous, use this:
http://www.devx.com/vb2themax/Tip/19090
0
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
Oh, I see what you want...you want to use any one of those characters as a delimeter.  Sorry.
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 240 total points
Comment Utility
The only way to accomplish this (without looping as requested) is to replace all the delimiters you are interested in with something else so you can use the Split() function:

Option Explicit

Private Sub Command1_Click()
    Dim i As Integer
    Dim a As Variant
   
    a = SplitDelimiter("hello you:can you?me", " :?")
    For i = LBound(a) To UBound(a)
        Debug.Print "a(" & i & ") = " & a(i)
    Next i
End Sub

Private Function SplitDelimiter(ByVal source As String, ByVal delimiters As String) As Variant
    Dim i As Integer
    Dim delimiter As String
   
    delimiter = Chr(1) & "/|\"" & Chr(1)" ' pick something unlikely to appear in the source string
    For i = 1 To Len(delimiters)
        source = Replace(source, Mid(delimiters, i, 1), delimiter)
    Next i
    SplitDelimiter = Split(source, delimiter)
End Function
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
VBA to format 3 77
Problem to the message 13 62
DO Loop not working 4 62
Macro which automatically sends attachment to Outlook 14 48
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now