Convert Ascii to string

sharky12345

Well-known Member
Joined
Aug 5, 2010
Messages
3,422
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

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
[Table="width:, class:grid"][tr][td="bgcolor:#C0C0C0"][/td][td="bgcolor:#C0C0C0"]
A​
[/td][td="bgcolor:#C0C0C0"]
B​
[/td][/tr][tr][td="bgcolor:#C0C0C0"]
1​
[/td][td]Now is the time for all good men …[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
2​
[/td][td="bgcolor:#E5E5E5"]078111119032105115032116104101032116105109101032102111114032097108108032103111111100032109101110032133[/td][td]A2: =Str2AscDec(A1)[/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
3​
[/td][td="bgcolor:#E5E5E5"]Now is the time for all good men …[/td][td]A3: =AscDec2Str(A2)[/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
4​
[/td][td][/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
5​
[/td][td][/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
6​
[/td][td]Now is the time for all good men …[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
7​
[/td][td="bgcolor:#E5E5E5"]4E6F77206973207468652074696D6520666F7220616C6C20676F6F64206D656E2085[/td][td]A7: =Str2AscHex(A6)[/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
8​
[/td][td="bgcolor:#E5E5E5"]Now is the time for all good men …[/td][td]A8: =AscHex2Str(A7)[/td][/tr]
[/table]


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,223,903
Messages
6,175,286
Members
452,631
Latest member
a_potato

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