0

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

E.g:

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?

1 Answers1

0

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
Caius Jard
  • 72,509
  • 5
  • 49
  • 80