Converting text to Unicode Little Endian hex

masagrator

New Member
Joined
Jan 30, 2019
Messages
6
Hello.
I want to add a script for Excel to convert text like in title.
I found something like this
Code:
Function CODEW(Character As String, Optional Unicode_value As Boolean = True, _               Optional Exact_functionality As Boolean = False) As Variant
' Exact Functionality returns exact Unicode for characters as AscW() does
' rather than Windows characters as Asc() does
  Dim Characters As String
   Dim i       As Long
   If Exact_functionality Then
      CODEW = AscW(Character)
      If Unicode_value Then CODEW = “U” & Hex(CODEW)
      Exit Function
   End If


   For i = 128 To 159 'where non-compliant
     Characters = Characters & Chr(i)
   Next i


   If InStr(1, Characters, Left$(Character, 1), vbBinaryCompare) Then
      CODEW = Asc(Character)
   Else
      CODEW = AscW(Character)
   End If
   If Unicode_value Then CODEW = “U” & Hex(CODEW)
End Function
But is working only for one letter and doesn't add 0 at the beginning before converting to Little Endian.
Can someone helpto edit this?
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
OK, maybe i put too big script. This is something smaller
Code:
Function CODEW(Character As String)      CODEW = "0" & Hex(AscW(Character))
End Function
But still is not working for words.
 
Upvote 0
Sorry for post under post, but what can I do? :D
Code:
Function Text2LE(Character As String)    Dim x As Long
    x = AscW(Character)
    If x < 16 Then
      Text2LE = "000" & Hex(AscW(Character))
      Text2LE = Right(Text2LE, 2) & Left(Text2LE, 2)
    ElseIf x < 256 Then
      Text2LE = "00" & Hex(AscW(Character))
      Text2LE = Right(Text2LE, 2) & Left(Text2LE, 2)
    Else
      Text2LE = "0" & Hex(AscW(Character))
      Text2LE = Right(Text2LE, 2) & Left(Text2LE, 2)
    End If
End Function
Only Issue now is repeat this after word is finished
 
Upvote 0
Perhaps you could give an example of what you're trying to do.
 
Upvote 0
Maybe this:

A​
B​
C​
1​
Input
Output
2​
Just ∵U4A0075007300740020003522B2: =RunninBear(A2)

Code:
Function RunninBear(sInp As String) As String
  Dim i             As Long
  Dim ab()          As Byte

  ab = StrConv(sInp, vbUnicode)

  For i = 0 To UBound(ab) Step 4
    RunninBear = RunninBear & Right("0" & Hex(ab(i)), 2) & Right("0" & Hex(ab(i + 2)), 2)
  Next i
  RunninBear = "U" & RunninBear
End Function
 
Upvote 0
OK, already made it.
This is what i wanted:
Code:
Function Text2LE(Character As String)
Dim x As Long
Dim a As String
Dim i As Long
c = Len(Character)
For i = 1 To c
a = Mid(Character, i, 1)
x = AscW(a)
If x < 16 Then
  LE = "000" & Hex(AscW(a))
ElseIf x < 256 Then
  LE = "00" & Hex(AscW(a))
Else
  LE = "0" & Hex(AscW(a))
End If
  Text2 = Right(LE, 2) & Left(LE, 2)
  Text2L = Text2L + Text2
Next i
  Text2LE = Text2L + "0000"
End Function
 
Upvote 0
That doesn't work correctly for Unicode characters.
 
Upvote 0
It doesn't matter. I wanted only to convert standard text, that have Unicode number 1-511.
4 zeroes at the end are just only for purpose to be supported by app I'm working on.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,526
Messages
6,114,122
Members
448,550
Latest member
CAT RG

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top