Posts: 8
Threads: 3
Joined: Jun 2004
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
Posts: 480
Threads: 24
Joined: Mar 2003
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.
Posts: 8
Threads: 3
Joined: Jun 2004
Thanks
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$.
Posts: 121
Threads: 20
Joined: Sep 2004
LEN(str$) returns the length of str$
8% of the teenage population smokes or has smoked pot. If you're one of the 2% who hasn't, copy and paste this in your signature.
Posts: 8
Threads: 3
Joined: Jun 2004
Thanks
Everything work correctly