Qbasicnews.com

Full Version: Cesar code
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have problem with cesar code. I would like encode my file: text.txt

from:
"I have dog"
to:
"L kdyh grj" (+3 to code of sign)

But I dont know how to read text from file sign to sing.

For read text (whole line) from file I use:
OPEN "filename" FOR INPUT AS #1
INPUT #1, text
CLOSE 1
1. use LINE INPUT instead of INPUT when reading from the file. That way, a comma in the text string won't be counted as a delimiter. Also, it might have been a typo, but CLOSE 1 should be CLOSE #1.

2. once you've read in the string, use MID$() to look at the individual letters:

Code:
Letter$ = MID$(TextString$, LocationWithinString%, 1)

3. then you can use ASC() and CHR$() to do the +3 to the letter:

Code:
Letter$ = CHR$( ASC( Letter$ ) + 3 )

*peace*

Meg.
Thanks Smile
I have one more problem.
I would like to know how long is "TextString$"

"I have dog" ("L kdyh grj") have 10 characters. Can QBasic count how many characters is in TextString$.
LEN(str$) returns the length of str$
Thanks Smile
Everything work correctly Big Grin