How to represent Unicode character in VB.Net String literal?

后端 未结 7 1785
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-03 20:41

I know you can put Unicode character codes in a VB.Net string like this:

str = Chr(&H0030) & \"More text\"

I would like to know how

7条回答
  •  误落风尘
    2020-12-03 21:23

    The C# language supports this with escapes:

    var str = "\u0030More text";
    

    But that isn't available in VB.NET. Beware that you almost certainly don't want to use Chr(), that is meant for legacy code that works with the default code page. You'll want ChrW() and pass the Unicode codepoint.

    Your specific example is not a problem, &H0030 is the code for "0" so you can simply put it directly in the string literal.

    Dim str As String = "0MoreText"
    

    You can use the Charmap.exe utility to copy and paste glyphs that don't have an easy ASCII code.

提交回复
热议问题