[VB6]檢查字串是否有中文或全形字

[VB6]檢查字串是否有中文或全形字

剛好遇到這個需求,做個紀錄


Function ContainsChtString(str) As Boolean
    '檢查字串是否包含中文或全形字
    Dim i As Integer
    Dim Rc As Boolean
    Rc = False
    For i = 1 To Len(str)
        If Asc(Mid(str, i, 1)) < 0 Then
            Rc = True
            Exit For
        End If
    Next
    ContainsChtString = Rc
End Function

資料來源:http://www.blueshop.com.tw/board/show.asp?subcde=BRD2004020116544916K&fumcde=&odr=cdt&odrtyp=1

感謝璉璉大提供另一個判斷,方式很簡單
判斷Binary方式計算長度(LenB)與一般方式計算長度(Len)是否相同,如果不同就是有中文或全形!!


LenB(StrConv(myString, vbFromUnicode)) > Len(myString) 

 


以下是簽名:


Microsoft MVP
Visual Studio and Development Technologies
(2005~2019/6) 
topcat
Blog:http://www.dotblogs.com.tw/topcat