gpt4 book ai didi

vba - 将 unicode 字符插入 VBA 字符串

转载 作者:行者123 更新时间:2023-12-02 09:30:56 25 4
gpt4 key购买 nike

在 Windows 7 上使用 MS Access 2003,我发现以下函数会删除 ANSI 字符串中的所有重音符号,将(例如)señor 更改为 senor:

Public Function RemoveAccents(ByVal inputString As String) As String
Const accentString As String = "ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÏÑÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðñòóóôõöùúûüýÿ"
Const nonAccentStr As String = "AAAAAACEEEEIIIIINOOOOOUUUUYaaaaaaceeeeiiiionoooooouuuuyy"
Dim i As Integer

For i = 1 To Len(accentString)
inputString = Replace(inputString, Mid(accentString, i, 1), Mid(nonAccentStr, i, 1), , , vbBinaryCompare)
Next i
RemoveAccents = inputString
End Function

但是当我尝试将带有 Caron (U-010D)(č)(HTML č) 的拉丁小写字母 C 添加到函数 ConstaccentString 中时,如下所示,

Const accentString As String = "ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÏÑÒÓÔÕÖÙÚÛÜÝàáâãäåç" & ChrW$(&H10D) & "èéêëìíîïðñòóóôõöùúûüýÿ"
Const nonAccentStr As String = "AAAAAACEEEEIIIIINOOOOOUUUUYaaaaaacceeeeiiiionoooooouuuuyy"

我无法运行该函数。是否有一种语法允许我调整此函数以从包含不属于 ANSI 字符集中的字符的字符串中去除变音符号?

最佳答案

常量声明中不能包含像 ChrW() 这样的函数。

已修订

如果您可以创建这些公共(public)变量而不是常量,那么这应该会为您解决:

Const cWithCaron As String = &H10D
Public accentString As String
Public nonAccentStr As String


Sub TestStrings()
Dim clnString As String

accentString = "ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÏÑÒÓÔÕÖÙÚÛÜÝàáâãäåç" & ChrW(cWithCaron) & "èéêëìíîïðñòóóôõöùúûüýÿ"

nonAccentStr = "AAAAAACEEEEIIIIINOOOOOUUUUYaaaaaacceeeeiiiionoooooouuuuyy"
'I added this variable to test the function:
clnString = RemoveAccents(accentString)
'And a message box to display the results:
MsgBox clnString = nonAccentStr

End Sub

Public Function RemoveAccents(ByVal inputString As String) As String

Dim i As Integer

For i = 1 To Len(accentString)

inputString = Replace(inputString, Mid(accentString, i, 1), Mid(nonAccentStr, i, 1), , , vbBinaryCompare)
Next i

RemoveAccents = inputString

End Function

关于vba - 将 unicode 字符插入 VBA 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15642786/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com