www.pudn.com > mo_gps.zip > CUtils.cls


VERSION 1.0 CLASS 
BEGIN 
  MultiUse = -1  'True 
END 
Attribute VB_Name = "CParseUtils" 
Attribute VB_GlobalNameSpace = False 
Attribute VB_Creatable = True 
Attribute VB_PredeclaredId = False 
Attribute VB_Exposed = False 
Attribute VB_Ext_KEY = "SavedWithClassBuilder" ,"Yes" 
Attribute VB_Ext_KEY = "Top_Level" ,"Yes" 
'Class name:    CParseUtils.cls 
'Author: 
'Date:          Dec 98 
'Description:   String parsing utilities 
'Comments: 
' 
'Revisions: 
 
Option Explicit 
 
Friend Function CountParts(sString As String, Optional sDelim As String) As Byte 
' returns the number of parts in the string. 
 
    Dim textPos As Integer 
    Dim maxPos As Integer 
    Dim cnt As Integer 
     
    If Len(sDelim) = 0 Then sDelim = "," 
     
    If Len(sString) = 0 Then 
        CountParts = 0 
        Exit Function 
    End If 
     
          textPos = 1 
          maxPos = Len(sString) 
          cnt = 0 
           
          Do While textPos <= maxPos 
                If Mid$(sString, textPos, 1) = sDelim Then 
                    cnt = cnt + 1 
                End If 
            textPos = textPos + 1 
          Loop 
           
    If cnt = 0 Then 
        CountParts = cnt 
    Else 
        CountParts = cnt + 1 
        End If 
         
End Function 
 
Friend Function Parse(ByVal sString As String, iReq As Integer, Optional sDelim As String) As String 
    Dim sSt As String 
    Dim iCnt As Integer 
    Dim iPos As Integer 
 
    If Len(sDelim) = 0 Then sDelim = "," 
    sSt = sString & sDelim 
    For iCnt = 1 To iReq 
        iPos = InStr(sSt, sDelim) 
        If iPos Then 
            If iCnt = iReq Then     ' Requested string 
                Parse = Left$(sSt, iPos - 1) 
                Exit For 
            End If 
             
            If iPos = Len(sSt) Then ' No string left 
                Parse = "" 
                Exit For 
            End If 
            sSt = Mid$(sSt, iPos + Len(sDelim)) 
        Else 
            Parse = sSt 
            Exit For 
        End If 
    Next iCnt 
End Function