需要删除 vb6 中所有 unicode 字符的代码

Need code for removing all unicode characters in vb6

我需要删除 vb6 字符串中所有 unicode 字符的代码。

Public Shared Function StripUnicodeCharactersFromString(ByVal inputValue As String) As String
    Return Regex.Replace(inputValue, "[^\u0000-\u007F]", String.Empty)
End Function

Vb6 - 不确定

sRTF = "\u" & CStr(AscW(char))

工作? - 您可以对所有大于 127

的字符值执行此操作

如果这是 UTF-16 文本(所有普通的 VB6 字符串值都是)并且您可以忽略代理项对的问题,那么这相当快速且相当简洁:

Private Sub DeleteNonAscii(ByRef Text As String)
    Dim I As Long
    Dim J As Long
    Dim Char As String

    I = 1
    For J = 1 To Len(Text)
        Char = Mid$(Text, J, 1)
        If (AscW(Char) And &HFFFF&) <= &H7F& Then
            Mid$(Text, I, 1) = Char
            I = I + 1
        End If
    Next
    Text = Left$(Text, I - 1)
End Sub

这解决了 VB6 在从 AscW() 函数返回带符号的 16 位整数时不得不做出的不幸选择。它本应与 ChrW$() 对称,但事实就是如此。

它应该在清晰度、可维护性和性能方面击败任何正则表达式库。如果真正大量的文本需要更好的性能,那么可以使用 SAFEARRAY 或 CopyMemory 特技。

StrConv是字符串转换命令

StrConv 函数

Returns 按指定转换的 Variant(字符串)。

语法

StrConv(string, conversion, LCID)

StrConv 函数语法具有这些命名参数:

部分描述

string Required. String expression to be converted. 

conversion Required. Integer. The sum of values specifying the type of conversion to perform. `128` is Unicode to local code page (or whatever the optional LCID is) 

LCID Optional. The LocaleID, if different than the system LocaleID. (The system LocaleID is the default.)