Convert Ascii to string

sharky12345

Well-known Member
Joined
Aug 5, 2010
Messages
3,404
Office Version
  1. 2016
Platform
  1. Windows
I'm using this to convert a string to ascii;

Code:
Public Function asciien(s As String) As String' Returns the string to its respective ascii numbers
   Dim i As Integer


   For i = 1 To Len(s)
      asciien = asciien & CStr(Asc(Mid(s, i, 1)))
   Next i


End Function

Can someone show me how to convert it back to string please?
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
A​
B​
1​
Now is the time for all good men …
2​
078111119032105115032116104101032116105109101032102111114032097108108032103111111100032109101110032133A2: =Str2AscDec(A1)
3​
Now is the time for all good men …A3: =AscDec2Str(A2)
4​
5​
6​
Now is the time for all good men …
7​
4E6F77206973207468652074696D6520666F7220616C6C20676F6F64206D656E2085A7: =Str2AscHex(A6)
8​
Now is the time for all good men …A8: =AscHex2Str(A7)

Code:
Function Str2AscHex(sInp As String) As String
    Dim i           As Long

    For i = 1& To Len(sInp)
        Str2AscHex = Str2AscHex & Right$("0" & Hex$(Asc(Mid$(sInp, i, 1&))), 2&)
    Next i
End Function

Function AscHex2Str(sInp As String) As String
    Dim i           As Long

    For i = 1& To Len(sInp) Step 2&
        AscHex2Str = AscHex2Str & Chr$("&H" & Mid$(sInp, i, 2&))
    Next i
End Function

Function Str2AscDec(sInp As String) As String
    Dim i           As Long

    For i = 1& To Len(sInp)
        Str2AscDec = Str2AscDec & Right$("00" & Asc(Mid$(sInp, i, 1&)), 3&)
    Next i
End Function

Function AscDec2Str(sInp As String) As String
    Dim i           As Long

    For i = 1& To Len(sInp) Step 3&
        AscDec2Str = AscDec2Str & Chr$(Mid$(sInp, i, 3&))
    Next i
End Function
 
Upvote 0

Forum statistics

Threads
1,214,978
Messages
6,122,549
Members
449,089
Latest member
davidcom

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