Home > Software engineering >  How to extract a UNICODE string? (use vb.net or c #)
How to extract a UNICODE string? (use vb.net or c #)

Time:11-03

To help the warrior! Online waiting for!

CodePudding user response:

If it is a simple VB is
Dim s as string
Dim (B) as byte

S=...
B=s

So, b in the array, the value of the every two adjacent bytes is the Unicode mama corresponding s characters

CodePudding user response:

No, 'a', for example, unicode code is 4 e00, I want this one

CodePudding user response:

refer to the second floor whoredsky response:
no, 'a', for example, unicode code is 4 e00, I want this


Do you have a try? Try don't!

Private Sub Command3_Click ()
Dim s As String
Dim (B) As Byte
S="a"
B=s

Dim As Long I
For I=0 To UBound (B)
The Debug. Print Hex (B) (I)
Next
End Sub

The result is:
0
4 e
2 a
4 e
BA
4 e

CodePudding user response:

Can B is equal to s type,

CodePudding user response:

Brothers and QQ chat more convenient! I was 2469431738 redsky

CodePudding user response:

The
reference 4 floor whoredsky reply:
can B is equal to s type,


I am crazy dizzy, can you try not to know, all give you, give you the result, also so ask!!

CodePudding user response:

Hey brother I've tried!
I also capture up what you said is what I use is vb.net,,,,,,,?

CodePudding user response:

Dizzy, I am a VB6
Such as.net. There should be a string tobyte conversion function,

CodePudding user response:

I have a few questions to ask warrior, you can add QQ detailed talk about? 2469431738, thanks!

CodePudding user response:

There is a problem to put out the problem, discussed in here

CodePudding user response:

? Hex (ascw (" a "))
4 e00

CodePudding user response:

Reference: http://blog.csdn.net/chenjl1031/article/details/6059767
 Option Explicit 
Private Declare Function MultiByteToWideChar Lib "kernel32. DLL" (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpMultiByteStr As String, ByVal cchMultiByte As Long, ByVal lpWideCharStr As String, ByVal cchWideChar As Long) As Long
Private Declare Function WideCharToMultiByte Lib "kernel32. DLL" (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long, ByRef lpMultiByteStr As Any, ByVal cchMultiByte As Long, ByVal lpDefaultChar As String, ByVal lpUsedDefaultChar As Long) As Long
Private Const CP_ACP As Long=0
Private Const CP_UTF8 As Long=65001

'the Ansi plain text files can be converted into Unicode (Little Endian) text file
Private Function AnsiToULE (ByVal Inputansifile As String, ByVal OutputULEfile As String) As Boolean
Dim Filebyte () As Byte, the sAnsi As String, FileNumber retLen As Long, As Long
Dim sUnicodeBuffer As String

On the Error Resume Next

'open the Ansi text file Inputansifile
FileNumber=FreeFile
If Dir (Inputansifile)="" Then AnsiToULE=False: Exit Function
The Open Inputansifile For Binary As # FileNumber
ReDim Filebyte (LOF (FileNumber) - 1)
The Get # FileNumber, Filebyte
Close # FileNumber

SAnsi=StrConv (Filebyte vbUnicode) 'into VB6 can display the string
RetLen=MultiByteToWideChar (CP_ACP, 0, sAnsi, LenB (sAnsi), vbNullChar, 0) 'obtained after transformation needs the space size retLen
SUnicodeBuffer=String $(LenB (sAnsi), vbNullChar) set the buffer size
'If retLen & gt; 0 Then
RetLen=MultiByteToWideChar (CP_ACP, 0, sAnsi, LenB (sAnsi), sUnicodeBuffer, retLen) began to convert
'The Else
AnsiToULE=False: Exit Function
End the If

'save as Unicode (Little Endian) text file OutputULEfile
If retLen & gt; 0 Then
FileNumber=FreeFile
If Dir (OutputULEfile) & lt;> "" Then Kill (OutputULEfile)
The Open OutputULEfile For Binary As # FileNumber
Put # FileNumber., & amp; HFEFF 'plus Unicode (Little Endian) file header BOM logo FFFE
Put # FileNumber, sUnicodeBuffer 'save the file content
Close # FileNumber
AnsiToULE=True
The Else
AnsiToULE=False: Exit Function
End the If
End the Function

Unicode Big Endian 'Ansi plain text files can be converted into a text file
Private Function AnsiToUBE (ByVal Inputansifile As String, ByVal OutputUBEfile As String) As Boolean
Dim Filebyte () As Byte, Fbyte () As Byte
Dim sAnsi As String, FileNumber retLen As Long, As Long
Dim sUnicodeBuffer As String
Dim As Long I

On the Error Resume Next

'open the Ansi text file Inputansifile
FileNumber=FreeFile
If Dir (Inputansifile)="" Then AnsiToUBE=False: Exit Function
The Open Inputansifile For Binary As # FileNumber
ReDim Filebyte (LOF (FileNumber) - 1)
The Get # FileNumber, Filebyte
Close # FileNumber

SAnsi=StrConv (Filebyte vbUnicode) 'into VB6 can display the string
RetLen=MultiByteToWideChar (CP_ACP, 0, sAnsi, LenB (sAnsi), vbNullChar, 0) 'obtained after transformation needs the space size retLen
SUnicodeBuffer=String $(LenB (sAnsi), vbNullChar) set the buffer size
'If retLen & gt; 0 Then
RetLen=MultiByteToWideChar (CP_ACP, 0, sAnsi, LenB (sAnsi), sUnicodeBuffer, retLen) began to convert
'The Else
AnsiToUBE=False: Exit Function
End the If

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related