[VBA] string processing

InStr function: Find string

. 1  Sub the InStr function ()
 2     Dim strTemp   of As  String 
. 3     strTemp = " = C = the AAA = the BBB " 
. 4     the Debug.Print the InStr (strTemp, " = " )        " " = "position first appears 
5     ' output. 1 
. 6     the Debug.Print the InStr ( 2 , strTemp, " = " )     ' 2: Find the second character 
7     ' output. 5 
. 8     strTemp = " AAABBBC " 
. 9     the Debug.Print The InStr (strTemp, " = " )        ' not found return 0 
10     ' outputs 0 
. 11  End Sub

Replace function: the replacement string

. 1  Sub the Replace function ()
 2      Dim strTemp of As  String 
. 3      strTemp = " the AAA = the BBB = C " 
. 4      the Debug.Print the Replace (strTemp, " A " , " A " )   ' A replaced with A 
. 5      ' output aaa = BBB = C 
6  End Sub

 Connection String

. 1  Sub connection string ()
 2      Dim strTemp of As  String 
. 3      strTemp = " the AAA " & " the BBB " & " C "    ' universal link character & 
. 4      the Debug.Print strTemp
 . 5      ' output AAABBBC 
. 6  End Sub

 Split function: segmentation string

. 1  Sub Split function ()
 2     Dim strTemp of As  String 
. 3     Dim A of As the Variant
 . 4     strTemp = " the AAA = the BBB = C " 
. 5     A = Split (strTemp, " = " )    ' split string 
. 6      the Debug.Print A ( 0 )
 . 7      ' output the AAA 
. 8      the Debug.Print A ( . 1 )
 . 9      ' outputs the BBB 
10      the Debug.Print A ( 2 )
 . 11      ' output C
12 End Sub

 

 

 

Guess you like

Origin www.cnblogs.com/KMould/p/11944242.html