This is an example that demonstrates how to convert a text string into its ASCII values.  In this example, conversion will also create a log of how each loop in the example script shows with text character the computer has assigned a number, and how that number can be used to convert the number back into its original character.

 

Standard ASCII Table:

This is the Standard ASCII table for converting text to an ASCII value, and for using the Chr() function to convert the ASCII number to a text character.

Click to Expand, Click to Reduce.

ASCII Character Reference Table

 

Example:

 
VARIABLES: n, iTextLen, iCharNum, iChar Type: Integer
VARIABLES: sText, sTxtChar,sTxtChar2, MyString Type: String
 
'  Assign String to Convert Character Values
sText = "<![CDATA[ xxxxxxx"
'  Determine the Length of the String
iTextLen = Len(sText)
'  Clear the Working Output String
MyString = ""
 
'  Let TB show the ASCII Characters for the String
For n = 1 TO iTextLen STEP 1
  ' Get 1 Character from a String
  sTxtChar = mid( sText, n, 1 )
  '  Convert Character to its ASCII Number
  iCharNum = ASCII(sTxtChar)
  '  Show What is happening on each cycle of the loop
  PRINT iCharNum," = ",sTxtChar
  '  Concatenate the results of the looping changes
  MyString = MyString + "Chr(" + AsString(iCharNum)+")+"
Next '  n
 
'  Remove the Last "+" from the created string
iTextLen = Len(MyString) - 1    
 
'  Update the created string without the "+" sign
MyString = Left(MyString,iTextLen)
 
'  Show processing Results
PRINT MyString

 

Results:

The information shown below is the output of create when each character is converted to ASCII, and the text value that number illustrates.

60  =  <

33  =  !

91  =  [

67  =  C

68  =  D

65  =  A

84  =  T

65  =  A

91  =  [

32  =    

120  =  x

120  =  x

120  =  x

120  =  x

120  =  x

120  =  x

120  =  x

Chr(60)+Chr(33)+Chr(91)+Chr(67)+Chr(68)+Chr(65)+Chr(84)+Chr(65)+Chr(91)+Chr(32)+Chr(120)+Chr(120)+Chr(120)+Chr(120)+Chr(120)+Chr(120)+Chr(120)

 

 

Links:

ASCII, ASCII To Characters

See Also:

Data Groups and Types

 


Edit Time: 9/18/2020 1:34:00 PM


Topic ID#: 78

 

 

Created with Help & Manual 7 and styled with Premium Pack Version 2.80 © by EC Software