CryptoSys PKI Pro Manual

Example: Cnv.CheckUTF8  Cnv.CheckUTF8Bytes  Cnv.UTF8BytesFromLatin1 

[VB6 equivalent: CNV_UTF8BytesFromLatin1]

Dim strData As String
Dim abDataUTF8() As Byte
Dim nRet As Integer

' Our original string data contains 5 non-ASCII characters
strData = "abcóéíáñ"
Console.WriteLine("Latin-1 string='{0}'", strData)
Console.WriteLine(" ({0} characters)", strData.Length)
' Convert directly to array of bytes in UTF-8 encoding
abDataUTF8 = System.Text.Encoding.UTF8.GetBytes(strData)
Console.WriteLine("UTF-8=(0x){0}'", Cnv.ToHex(abDataUTF8))
Console.WriteLine(" ({0} bytes)", abDataUTF8.Length)

' Check if this is valid UTF-8 encoding
nRet = Cnv.CheckUTF8(abDataUTF8)
Console.WriteLine("Cnv.CheckUTF8Bytes returns {0} (expected 2)", nRet)

' Now put back into a string
Dim strNew = System.Text.Encoding.UTF8.GetString(abDataUTF8)
Console.WriteLine("New string='{0}' ({1} characters)", strNew, strNew.Length)

See Also:

[Contents] [Index]

[PREV: Example: Cnv.ByteEncoding ...]   [Contents]   [Index]   
   [NEXT: Example: Hash.Bytes ...]

Copyright © 2004-23 D.I. Management Services Pty Ltd. All rights reserved. Generated 2023-09-18T10:02:53Z.