简体   繁体   中英

Contains is unable to find VbTab & Chr

Contains is unable to find VbTab & Chr(...)

    Public Function GetBullet(Txt As String) As String
        GetBullet = ""
        If Txt.Contains(vbTab & Chr(149)) Then GetBullet = Chr(149)
        If Txt.Contains(vbTab & Chr(176)) Then GetBullet = Chr(176)
        If Txt.Contains(vbTab & Chr(183)) Then GetBullet = Chr(183)
        If Txt.Contains(vbTab & Chr(187)) Then GetBullet = Chr(187)
    End Function

Eg:

Txt: vbTab & "・My text"

Asc(Mid(Txt,2,1)) returns 183

GetBullet returns "" at the end of the function

Is it a bug or did I write something wrong?

Strings in .net are unicode. Your posted string contains char 12539, not 183

If Txt.Contains(vbTab & ChrW(12539)) Then GetBullet = ChrW(12539)
                           ^                             ^
                       important                     important

In other words:

AscW(Mid(Txt,2,1)) returns 12539
   ^
important

Perhaps switching to modern .net versions rather than old legacy VB helper functions will be better:

If Txt.Contains(vbTab & Convert.ToChar(12539)) Then GetBullet = Convert.ToChar(12539)

'index strings by 0 based index to get the char at that index
'Txt(1) is the second character in Txt
Convert.ToInt32(Txt(1)) returns 12539

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM