Before You Post, Please Note...

-> Please Note: By Posting, you agree to submit the contents of your post to the Public Domain <- SEE: howto post to this blog

Friday, February 2, 2007

puppybasic intro ch. 05 - strings part i

green text is being edited and should not be considered  
relevant to the tutorial.
for a while, it will make up
the bulk of this section.

black text has been edited to be more accurate with
regards to puppybasic.

........................................................................
strings part i: the indispensable
1 of 7




an intro to puppybasic

chapter 5: strings part i







........................................................................

........................................................................
strings part i: the indispensable
2 of 7

although you need to talk to the computer to write a program, and you
usually need math to talk to the computer, you usually need strings
(which may contain plain english) to talk to the person using the
computer. for this and other reasons, strings are generally as vital to
your program as numbers. here are some statements to work with strings:

UCASE$

q$=UCASE$(q$) will convert q$ to an all uppercase copy of itself. the
lowercase version is:



........................................................................

........................................................................
strings part i: the indispensable
3 of 7

LCASE$

q$=LCASE$(q$) when you've printed "press q to quit" can be the
difference between a person being able to exit your program when they
want to and being able to a bit later (when someone points out that
their caps lock light is on.) it is possible to turn off someone's caps
lock for them using program code, but processing strings with LCASE$ is
easier and more considerate.
_________________________________
q$="NAME@PUPPY.Com": PRINT LCASE$(q$) _name@puppy.com__________________
_________________________________


........................................................................

........................................................................
strings part i: the indispensable
4 of 7

CHR$ is indispensable: there are 256 different ASCII characters, (for
example, the lowercase letter "a" is ASCII 97, and a space, like from
the spacebar, is ASCII 32.) including letters, numbers, punctuation, and
other fun symbols (ASCII 01 is a smiley face. ☺ for the most part, the
only way to produce some of them is with CHR$. for instance, if you want
to produce a double quote on the screen, or within a string, you can use
the following code: (put it all on the same line, of course...)
? "i have been learning about puppybasic from "+CHR$(34)+"an intro to
puppybasic"+CHR$(34)+" and it's okay..."

...as ASCII 34 is the same double quote you would get from the keyboard.


........................................................................

........................................................................
strings part i: the indispensable
5 of 7

+------+---------------------------------------------------------------+
| CHR$ | also lets you "print" shadows and lines using text symbols... |
+------+---------------------------------------------------------------+
the reverse of CHR$, the ASC function, gives you the code number for the
first byte of a string:

? ASC("a") -3 _________________________________________________________
will print: __94_____________________________________________________
_________________________________________________________

as ascii 97, in puppybasic coded as: CHR$(97) is "a", and 97 -3 is 94.


........................................................................

........................................................................
strings part i: the indispensable
6 of 7

LEN... n = LEN(q$) will set n to a number equal to the number of bytes
in a string - examples: LEN("hello") is equal to 5, LEN("how are you?")
is equal to twelve. spaces and punctuation count.

lastly, as you can convert a string to a number using VAL, you can
convert a number to a string using STR$ so:

sp = 5
q$ = "you pressed spacebar" + STR$(sp-1) + "times."

will store the string: "you pressed spacebar 4 times." in q$.


........................................................................

........................................................................
strings part i: the indispensable
7 of 7

you are well on your way to learning puppybasic! the best thing you can
do with this tutorial is read it slowly, think about each page and what
kind of program you could write with each command, and experiment with
the code in puppybasic (type it in, you learn faster that way, even
though you *could* cut and paste...) for a feel of what coding is really
like.

and never forget to have fun.

-= end of chapter 5 =-



........................................................................
an intro to puppybasic (chapter 5)
this content is public domain.
........................................................................


click here to go back to the contents page

0 comments: