Unicode in vb.net 2003

Dear all,

I have two fields in sql server 2005.These two fields are store unicode data.

Field A hava a string "Hello" and another Field B also have a string "Hello"

When I try to compare Field A and Field B in VB.net 2003, I found these two strings are NOT equal.

Under this case ,How can I compare these two strings?

Thanks you

[386 byte] By [LeeJohn] at [2007-12-28]
# 1

Applications that target the common language runtime use encoding to map character representations from the native character scheme (Unicode) to other schemes. Applications use decoding to map characters from nonnative schemes (non-Unicode) to the native scheme. The System.Text namespace provides classes that allow you to encode and decode characters. System.Text encoding support includes the following encodings:

Unicode UTF-16 encoding

Unicode UTF-16 encoding represents Unicode characters as sequences of 16-bit integers. You can use the UnicodeEncoding class to convert characters to and from UTF-16 encoding.

Unicode UTF-8 encoding

Unicode UTF-8 encoding represents Unicode characters as sequences of 8-bit bytes. You can use the UTF8Encoding class to convert characters to and from UTF-8 encoding.

ASCII encoding

ASCII encoding encodes the Latin alphabet as single 7-bit ASCII characters. Because this encoding only supports character values from U+0000 through U+007F, in most cases it is inadequate for internationalized applications. You can use the ASCIIEncoding class to convert characters to and from ASCII encoding. For examples of using the ASCIIEncoding class in code, see Encoding Base Types.

ANSI/ISO Encodings

The System.Text.Encoding class provides support for a wide range of ANSI/ISO encodings.

Using the Encoding Class

You can use the Encoding.GetEncoding method to return an encoding object for a specified encoding. You can use the Encoding.GetBytes method to convert a Unicode string to its byte representation in a specified encoding.

The following code example uses the Encoding.GetEncoding method to create a target encoding object for a specified code page. The Encoding.GetBytes method is called on the target encoding object to convert a Unicode string to its byte representation in the target encoding. The byte representations of the strings in the specified code pages are displayed.

[Visual Basic]

Imports System

Imports System.IO

Imports System.Globalization

Imports System.Text

Public Class Encoding_UnicodeToCP

Public Shared Sub Main()

' Converts ASCII characters to bytes.

' Displays the string's byte representation in the

' specified code page.

' Code page 1252 represents Latin characters.

PrintCPBytes("Hello, World!", 1252)

' Code page 932 represents Japanese characters.

PrintCPBytes("Hello, World!", 932)
' Converts Japanese characters.

PrintCPBytes("\u307b,\u308b,\u305a,\u3042,\u306d",1252)

PrintCPBytes("\u307b,\u308b,\u305a,\u3042,\u306d",932)

End Sub

Public Shared Sub PrintCPBytes(str As String, codePage As Integer)

Dim targetEncoding As Encoding

Dim encodedChars() As Byte
' Gets the encoding for the specified code page.

targetEncoding = Encoding.GetEncoding(codePage)
' Gets the byte representation of the specified string.

encodedChars = targetEncoding.GetBytes(str)
' Prints the bytes.

Console.WriteLine("Byte representation of '{0}' in CP '{1}':", _

str, codePage)

Dim i As Integer

For i = 0 To encodedChars.Length - 1

Console.WriteLine("Byte {0}: {1}", i, encodedChars(i))

Next i

End Sub

End Class

 
Regards,
S_DS
P.S. Are you sure one of the strings hasn't got a full-stop or a space character you've missed?
 
 
 
Spidermans_DarkSide at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2

I use this and works perfect for me:

Dim result as integer

Dim a as string

Dim b as string

a= "Hello"

b="Hello"

result = StrComp(a, b, vbTextCompare)

if result=0 then

' The strings are identical

end if

Hope this helps.

godog_vb at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic General...