MS Excel自定义unicode函数

MS Excel自定义unicode函数,excel,vba,unicode,Excel,Vba,Unicode,我在Excel文件的一列中有一个IPA符号列表,如下所示: a ɒ ɒ̃ ɑː æ aɪ aʊ aʊə b ɔː 我使用unicode函数获取每个字符的值。这只适用于单个字符,因此我正在尝试编写一个自定义函数,该函数将返回每个字符的值,每个字符由一个字符分隔 但是,该函数不能识别某些(非字母)字符,如ɒ̃和æ 有人知道我做错了什么吗 我已将代码粘贴到下面: Public Function UnicodeText(text2convert As String) Dim textLen As In

我在Excel文件的一列中有一个IPA符号列表,如下所示:

a
ɒ
ɒ̃
ɑː
æ
aɪ
aʊ
aʊə
b
ɔː
我使用unicode函数获取每个字符的值。这只适用于单个字符,因此我正在尝试编写一个自定义函数,该函数将返回每个字符的值,每个字符由一个字符分隔

但是,该函数不能识别某些(非字母)字符,如ɒ̃和æ

有人知道我做错了什么吗

我已将代码粘贴到下面:

Public Function UnicodeText(text2convert As String)
Dim textLen As Integer
UnicodeText = ""
textLen = Len(text2convert)

If Len(text2convert) = 1 Then
    UnicodeText = Asc(text2convert)
Else
    For i = 1 To textLen
        If i = 1 Then
           UnicodeText = UnicodeText & Asc(Left(text2convert, 1)) & "."
        Else
           If i = textLen Then
              UnicodeText = UnicodeText & Asc(Right(text2convert, 1))
           Else
              UnicodeText = UnicodeText & Asc(Mid(text2convert, i, 1)) & "."
           End If
       End If
 Next i

End If

End Function
Option Explicit
Function uni(S As String) As String
    Dim I As Long
    Dim sTemp As String

sTemp = ""
For I = 1 To Len(S)
    sTemp = sTemp & "." & AscW(Mid(S, I, 1))
Next I

uni = Mid(sTemp, 2)

End Function
此外,它还将字符ɒ̃识别为长度为2


这样做的原因是为了确保使用的字符与某些字体中的字符(如ɡ和g)相同,但实际上是两个不同的字符。

如果我了解您要正确执行的操作,您可以使用
AscW
功能。
AscW
函数返回字符串的Unicode字符

您可以将代码中的
Asc
替换为
AscW
,也可以使用以下代码:

Public Function UnicodeText(text2convert As String)
Dim textLen As Integer
UnicodeText = ""
textLen = Len(text2convert)

If Len(text2convert) = 1 Then
    UnicodeText = Asc(text2convert)
Else
    For i = 1 To textLen
        If i = 1 Then
           UnicodeText = UnicodeText & Asc(Left(text2convert, 1)) & "."
        Else
           If i = textLen Then
              UnicodeText = UnicodeText & Asc(Right(text2convert, 1))
           Else
              UnicodeText = UnicodeText & Asc(Mid(text2convert, i, 1)) & "."
           End If
       End If
 Next i

End If

End Function
Option Explicit
Function uni(S As String) As String
    Dim I As Long
    Dim sTemp As String

sTemp = ""
For I = 1 To Len(S)
    sTemp = sTemp & "." & AscW(Mid(S, I, 1))
Next I

uni = Mid(sTemp, 2)

End Function

顺便说一下,如果您有O365
TEXTJOIN
SEQUENCE
函数,您可以使用以下工作表公式:

=TEXTJOIN(".",TRUE,UNICODE(MID(A1,SEQUENCE(LEN(A1)),1)))
如果您有
TEXTJOIN
但没有
SEQUENCE
函数,则可以将
SEQUENCE
函数调用替换为
行(索引($A:$A,1):索引($A:$A,LEN(A1))


如果我正确理解了您要执行的操作,您可以使用
AscW
功能。
AscW
函数返回字符串的Unicode字符

您可以将代码中的
Asc
替换为
AscW
,也可以使用以下代码:

Public Function UnicodeText(text2convert As String)
Dim textLen As Integer
UnicodeText = ""
textLen = Len(text2convert)

If Len(text2convert) = 1 Then
    UnicodeText = Asc(text2convert)
Else
    For i = 1 To textLen
        If i = 1 Then
           UnicodeText = UnicodeText & Asc(Left(text2convert, 1)) & "."
        Else
           If i = textLen Then
              UnicodeText = UnicodeText & Asc(Right(text2convert, 1))
           Else
              UnicodeText = UnicodeText & Asc(Mid(text2convert, i, 1)) & "."
           End If
       End If
 Next i

End If

End Function
Option Explicit
Function uni(S As String) As String
    Dim I As Long
    Dim sTemp As String

sTemp = ""
For I = 1 To Len(S)
    sTemp = sTemp & "." & AscW(Mid(S, I, 1))
Next I

uni = Mid(sTemp, 2)

End Function

顺便说一下,如果您有O365
TEXTJOIN
SEQUENCE
函数,您可以使用以下工作表公式:

=TEXTJOIN(".",TRUE,UNICODE(MID(A1,SEQUENCE(LEN(A1)),1)))
如果您有
TEXTJOIN
但没有
SEQUENCE
函数,则可以将
SEQUENCE
函数调用替换为
行(索引($A:$A,1):索引($A:$A,LEN(A1))

字符(代码)与UNICHAR(UNICODE) 这里没有解决办法。这只是对这里发生的事情的视觉解释。它显示了
AC
列与
code
列与
EFG
列之间的“转换”,以及
UNICODE
列与
HIJ
列之间的“转换”,然后使用
CHAR
列与
KLM
列之间的转换,以及
UNICHAR
列与
NOP
列之间的转换。列
Q
表示OP函数的结果,而列
RS
表示Jon Rosenfeld的解的结果。下面我添加了我语言中的关键字符

CHAR(代码)与UNICHAR(UNICODE) 这里没有解决办法。这只是对这里发生的事情的视觉解释。它显示了
AC
列与
code
列与
EFG
列之间的“转换”,以及
UNICODE
列与
HIJ
列之间的“转换”,然后使用
CHAR
列与
KLM
列之间的转换,以及
UNICHAR
列与
NOP
列之间的转换。列
Q
表示OP函数的结果,而列
RS
表示Jon Rosenfeld的解的结果。下面我添加了我语言中的关键字符


谢谢你,罗恩。我没有O365,所以我只使用了AscW功能,它似乎工作正常。谢谢Ron。我没有O365,所以我只是使用了AscW功能,它似乎工作正常。谢谢VBASIC208。。。。这张照片帮助我了解了发生了什么。谢谢VBASIC208。。。。这张照片帮助我了解了发生的事情。