# CHR\$

The CHR\$ function returns the character associated with a certain character code as a STRING.

result\$ = CHR\$(code%)

Description:

• Valid ASCII code numbers range from 0 to 255.
• The character code of a character can be found using ASC.
• Some control codes below 32 will not PRINT or will move the screen cursor.

Code Examples:

Example 1: Outputs the characters of several character codes:

PRINT CHR\$(65); CHR\$(65 + 32) PRINT CHR\$(66); CHR\$(66 + 32)

Aa Bb

Explanation: 65 is the ASCII code for "A" and 65 + 32 is the ASCII code for "a". 66 is the ASCII code for "B" and 66 + 32 is the ASCII code for "b"

Example 2: To cut down on typing CHR\$(???) all day, define often used characters as variables such as Q\$ = CHR\$(34) as shown.

DIM Q AS STRING * 1 'define as one byte string(get rid of \$ type suffix too) Q = CHR\$(34) 'Q will now represent the elusive quotation mark in a string PRINT "This text uses "; Q; "quotation marks"; Q; " that could have caused a syntax error!"

This text uses "quotation marks" that could have caused a syntax error!

Example 3: Using ASC and CHR\$ to Encrypt a text file size up to 32K bytes

OPEN FileName\$ FOR INPUT AS #1 ' FileName to be encrypted IF LOF(1) <= 32000 THEN Text\$ = INPUT\$(LOF(1), 1) ' get Text as one string CLOSE #1 Send\$ = "" ' clear value FOR i = 1 TO LEN(Text\$) Letter\$ = MID\$(Text\$, i, 1) ' get each character in the text Code = ASC(Letter\$) IF (Code > 64 AND Code < 91) OR (Code > 96 AND Code < 123) THEN Letter\$ = CHR\$(Code + 130) ' change letter's ASCII character by 130 END IF Send\$ = Send\$ + Letter\$ ' reassemble string with just letters encrypted NEXT i OPEN FileName\$ FOR OUTPUT AS #1 ' erase FileName to be encrypted PRINT #1, Send\$ ' Text as one string CLOSE #1

Warning: Above routine will change ORIGINAL text file to be unreadable!
Use a second Filename to preserve the original file!

Example 4: Decrypting the above encrypted text file (32K byte file size limit).

OPEN FileName\$ FOR INPUT AS #1 ' FileName to be decrypted Text\$ = INPUT\$(LOF(1), 1) ' open Text as one string CLOSE #1 Send\$ = "" FOR i = 1 TO LEN(Text\$) Letter\$ = MID\$(Text\$, i, 1) Code = ASC(Letter\$) IF (Code > 194 AND Code < 221) OR (Code > 226 AND Code < 253) THEN Letter\$ = CHR\$(Code - 130) ' change back to a Letter character END IF Send\$ = Send\$ + Letter\$ ' reassemble string as normal letters NEXT i OPEN FileName\$ FOR OUTPUT AS #1 ' Erase file for decrypted text PRINT #1, Send\$ ' place Text as one string CLOSE #1

Code by Ted Weissgerber
Explanation: Examples 3 and 4 Encrypt and Decrypt a file up to 32 thousand bytes only! INPUT\$ can only get strings less than 32767 characters. The upper and lower case letter characters are the only ones altered, but the encryption and decryption rely on the fact that MOST text files do not use the code characters above 193. You could alter any character from ASCII 32 to 125 without problems using the 130 adder. NO ASCII code above 255 is allowed! DON'T alter the codes below code 32 as they are Control characters. Specifically, characters 13 and 10 (CrLf) may be used for line returns in text files.
{"ft_lang_label":"__label__en","ft_lang_prob":0.73838526,"math_prob":0.9117437,"size":3231,"snap":"2019-43-2019-47","text_gpt3_token_len":869,"char_repetition_ratio":0.13572977,"word_repetition_ratio":0.15359478,"special_character_ratio":0.3101207,"punctuation_ratio":0.0815047,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9605181,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-11-20T17:43:44Z\",\"WARC-Record-ID\":\"<urn:uuid:df62b864-b8ca-4389-9f8a-d423c2e39ce4>\",\"Content-Length\":\"19644\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:efaa2e97-dc28-4c5e-81d1-fd87547e0ede>\",\"WARC-Concurrent-To\":\"<urn:uuid:0304d5bd-462b-41b9-bcee-cf96c6896e7b>\",\"WARC-IP-Address\":\"145.239.125.73\",\"WARC-Target-URI\":\"http://www.qb64.net/wiki/index_title_CHR_/\",\"WARC-Payload-Digest\":\"sha1:7EHQO5MZSVARWCXSWMEIRBWOCH5AUTIC\",\"WARC-Block-Digest\":\"sha1:Y2ZIUZYJWVNGFHEBJF6YINXWU2SOCQ2O\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-47/CC-MAIN-2019-47_segments_1573496670597.74_warc_CC-MAIN-20191120162215-20191120190215-00323.warc.gz\"}"}