在B4A的英文使用手冊中,有提到一些VB6的指令和B4A中的差異,我把它擷錄出來,並且附上中文說明,希望對VB6轉B4A的程式設計師們,可以更快進入B4A的世界中:
Sub Left(Text As String, Length As Long)As String'從左邊抓幾個字
If Length>Text.Length Then Length=Text.Length
Return Text.SubString2(0, Length)
End Sub
Sub Right(Text As String, Length As Long) As String'從右邊抓幾個字
If Length>Text.Length Then Length=Text.Length
Return Text.SubString(Text.Length-Length)
End Sub
Sub Mid(Text As String, Start As Int, Length As Int) As String'從start開始抓length個字
Return Text.SubString2(Start-1,Start+Length-1)
End Sub
Sub Split(Text As String, Delimiter As String) As String()
'Dim s() As String
'Dim i As Integer
's() = Split("a b c d e", " ")
'則abcde則依序放入s陣列中
Return Regex.Split(Delimiter,Text)
End Sub
Sub Len(Text As String) As Int'傳回文字長度
Return Text.Length
End Sub
Sub Replace(Text As String,str As String,str2 As String)'將字串中的str換成str2
Text.Replace(str, str2)
End Sub
Sub Lcase(Text As String) As String'將文字改為小寫
Return Text.ToLowerCase
End Sub
Sub Ucase(Text As String) As String'將文字改為大寫
Return Text.ToUpperCase
End Sub
Sub Trim(Text As String) As String'將文字的左右空白去除
Return Text.Trim
End Sub
Sub Instr(Start As Int,Text As String, Str As String) As Int'在Text搜尋Str的位置,從第start個字開始找
Return Text.IndexOf2(Str,Start)
End Sub
Sub InStrRev(Text As String, Str As String) As Int'在Text搜尋Str的位置,從最右邊找回來
Text.LastIndexOf(Str)
End Sub
希望對大家有幫助
Sub Left(Text As String, Length As Long)As String'從左邊抓幾個字
If Length>Text.Length Then Length=Text.Length
Return Text.SubString2(0, Length)
End Sub
Sub Right(Text As String, Length As Long) As String'從右邊抓幾個字
If Length>Text.Length Then Length=Text.Length
Return Text.SubString(Text.Length-Length)
End Sub
Sub Mid(Text As String, Start As Int, Length As Int) As String'從start開始抓length個字
Return Text.SubString2(Start-1,Start+Length-1)
End Sub
Sub Split(Text As String, Delimiter As String) As String()
'Dim s() As String
'Dim i As Integer
's() = Split("a b c d e", " ")
'則abcde則依序放入s陣列中
Return Regex.Split(Delimiter,Text)
End Sub
Sub Len(Text As String) As Int'傳回文字長度
Return Text.Length
End Sub
Sub Replace(Text As String,str As String,str2 As String)'將字串中的str換成str2
Text.Replace(str, str2)
End Sub
Sub Lcase(Text As String) As String'將文字改為小寫
Return Text.ToLowerCase
End Sub
Sub Ucase(Text As String) As String'將文字改為大寫
Return Text.ToUpperCase
End Sub
Sub Trim(Text As String) As String'將文字的左右空白去除
Return Text.Trim
End Sub
Sub Instr(Start As Int,Text As String, Str As String) As Int'在Text搜尋Str的位置,從第start個字開始找
Return Text.IndexOf2(Str,Start)
End Sub
Sub InStrRev(Text As String, Str As String) As Int'在Text搜尋Str的位置,從最右邊找回來
Text.LastIndexOf(Str)
End Sub
希望對大家有幫助