modword.bas

来自「字符串分解程序」· BAS 代码 · 共 56 行

BAS
56
字号
Attribute VB_Name = "modWord"
Option Explicit



' #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
'   ParseString: Parses the string into multiple words
' #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
Public Function ParseString(StringToParse As String, _
    Optional Delimiter As String = " ") As Collection
    
    Dim colTemp     As Collection
    Dim objWord     As Word
    
    Dim lngStartPos As Long
    Dim lngNextPos  As Long
    
    Dim strTemp     As String
    
    ' Initialize the StartPosition and the Collection
    lngStartPos = 1
    Set colTemp = New Collection
    
    Do
        ' Clear any reference to a previous word
        Set objWord = Nothing
        
        ' Search the string
        lngNextPos = InStr(lngStartPos, StringToParse, Delimiter)
        
        If lngNextPos = 0 Then
            ' For when we get to the end of the file
            strTemp = Mid$(StringToParse, lngStartPos, Len(StringToParse) - lngNextPos + 1)
        Else
            strTemp = Mid$(StringToParse, lngStartPos, lngNextPos - lngStartPos + 1)
        End If
    
        lngStartPos = lngNextPos + 1
        
        Set objWord = New Word
        
        objWord.Value = strTemp
        colTemp.Add objWord
        DoEvents
    
    Loop Until lngNextPos = 0
    
ParseString_Exit:
    Set ParseString = colTemp
    Set objWord = Nothing
    Set colTemp = Nothing
End Function



⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?