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 ii: searching and manipulation
1 of 8
an intro to puppybasic
chapter 8: strings part ii
........................................................................
........................................................................
strings part ii: searching and manipulation
2 of 8
although you could find a better routine to do the same thing, INSTR is
a very fast and simple way to see if and when a string exists as part of
a larger string: for instance:
suppose q$ is storing the string:
"the quick brown fox jumped, and stuff."
and you want to know if the string (let's pretend you don't know what q$
is; maybe it's from a file or the keyboard.) contains the word "fox" so
you code:
........................................................................
........................................................................
strings part ii: searching and manipulation
3 of 8
n = INSTR(q$, "fox")
n will be equal to the number of letters, numbers, and punctuation that
you have to read before you've started reading "fox"... in this case,
the "f" in "fox" is the 17th byte in q$, so INSTR will set n to 17. if
the string "fox" is not found in the string that q$ is storing, n will
be set to 0.
1
123456789012345 7 90123456789012345678
"the quick brown fox jumped, and stuff."
........................................................................
........................................................................
strings part ii: searching and manipulation
4 of 8
SPACE$
is really, really easy to use. SPACE$(n) is a string of ascii 32 (space)
that is n bytes long. q$=q$+SPACE$(10) will add 10 spaces to the end of
q$.
LEFT$ and RIGHT$
are not as powerful or complete as MID$ but are slightly easier to use.
skipping straight to examples, LEFT$("Seventy",5) is "Seven" and
RIGHT$("elephant",3) is "ant". MID$ is similar:
........................................................................
........................................................................
strings part ii: searching and manipulation
5 of 8
the syntax for the MID$ function is:
MID$(q$, whichbytetostartat, howmanybytes)
so n$=MID$("hello", 2, 4) would set n$ to "ello" and
n$=MID$("yeah, or... something", 14, 2) would set n$ to "om".
there is a MID$ statement as well, which works the same way, except
instead of reading a string it will rewrite it:
........................................................................
........................................................................
strings part ii: searching and manipulation
6 of 8
y$="yeah, or... something"
n$=SPACE$(2)+"no"
MID$(y$, 13, 4)=n$
will store "yeah, or... nothing" in y$. the 4-byte "some" has been
replaced with 2 spaces and "no", changing "something" to " nothing".
whoosh!
........................................................................
........................................................................
strings part ii: searching and manipulation
7 of 8
if you do not like the MID$ statement for rewriting, it is totally
possible to avoid it entirely using only the MID$ "reading" function
and concatonization of strings.
there are times (especially with code like the first menu routine,
earlier) when your variable will have leading or trailing spaces that
you don't want. when you use STR$(n) to convert a numeric variable to a
string for instance, it will contain a leading space (if it is at least
zero) for a plus sign, even though the plus sign will never show. if the
number drops below zero, a negative sign will show, but otherwise, you
may be stuck with a space you don't want, like this: " 55".
........................................................................
........................................................................
strings part ii: searching and manipulation
8 of 8
LTRIM$(STR$(n))
will remove the leading spaces from a number, and LTRIM$(RTRIM$(q$))
will remove the spaces from both ends of any string. this is not only
useful when changing numbers to strings, but also when accepting
keyboard input or data from files.
-= end of chapter 8 =-
........................................................................
an intro to puppybasic (chapter 8)
this content is public domain.
........................................................................
click here to go back to the contents page
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. 08 - strings part ii
Subscribe to:
Post Comments (Atom)
31 comments:
Pills For Suicide Sources fartonast
Buy Valium Online Without Prescription
Valium acts upon the brain by affecting the neurotransmitter gamma-aminobutyric acid, and bringing about a calm euphoric state over the user.
[url=http://www.lianesorenson.com/]Buy Generic Valium[/url]
You may be wondering more about how Valium can help you with your social anxiety disorder or insomnia so we will outline some pros and cons of the medication below.
http://www.lianesorenson.com/ - Generic Valium Online
If you begin to experience adverse side effects let your doctor know immediately so he can make the proper adjustments.
cheap citalopram
Buy Celexa (Citalopram) online and save your money.
[url=http://www.naplesdirectory.org/]citalopram drug[/url]
How Celexa works?
For brain to communicate with other parts or within itself it uses special chemical called serotonin, which acts as a neurotransmitter.
http://www.naplesdirectory.org/ - cheap celexa
Celexa is an SSRI (Selective Serotonin Re Uptake Inhibitor) category medicine and can be used to reduce the cholesterol content in the blood.
buy tramadol online dosage of tramadol 50mg - tramadol high how much
buy tramadol online how to buy tramadol online overnight - tramadol 50mg 100ct
buy tramadol online tramadol hcl xr 200 mg - does tramadol 50mg look like
tramadol 50 mg tramadol for dogs effects - buy tramadol 100mg online
buy tramadol online can overdose tramadol kill you - signs of tramadol overdose
buy tramadol online where to buy tramadol cod - buy tramadol in europe
buy cheap tramadol buy tramadol from usa - tramadol hcl half life
order carisoprodol online carisoprodol 350 mg looks like - carisoprodol 100mg
carisoprodol 350 mg carisoprodol manufacturers - high off carisoprodol
tramadol online tramadol for dogs with pancreatitis - tramadol for dogs how often
order xanax happens you overdose xanax - difference between xanax bars xanax pills
buy tramadol online has bought tramadol online - tramadol drug class
buy cialis online in usa cialis online in new zealand - cialis joint pain
cialis price cialis 5mg tablets price - cheap cialis from usa
buy cialis usa cheap cialis eu - how to buy cialis over the counter
buy cialis online cialis 20 mg usa - generic cialis manufacturers us
cialis online usa drugs online cialis - cialis online best place buy
tramadol online cod tramadol withdrawal nightmares - buy tramadol online nz
buy tramadol online the tramadol high - order tramadol online us pharmacy
http://landvoicelearning.com/#23561 buy tramadol online legit - tramadol in usa over the counter
generic tramadol online tramadol for dogs online - tramadol 100mg 50mg
buy tramadol order tramadol online to florida - tramadol long before addiction
order tramadol online overnight tramadol 50 mg buy online - buy tramadol online bluelight
learn how to buy tramdadol tramadol n024 - can you buy tramadol in usa
buy tramadol in florida buy tramadol ultram - 100mg tramadol withdrawal
http://landvoicelearning.com/#51602 tramadol ultram pregnancy - tramadol online delivered florida
ways to buy ativan online how to taper off of 1 mg lorazepam - ativan dosage child
http://reidmoody.com/#54126 ativan gi side effects - ativan generic trade name
buy tramadol cod overnight tramadol hcl breastfeeding - tramadol 50mg for dogs side effects
http://staam.org/#90723 tramadol and pregnancy - tramadol que contiene
Post a Comment