Page 1 of 1
How-to strip the first & last character from a string ???
Posted: Fri Mar 15, 2013 7:27 pm
by RBSe
Greetings Daniel,
I have a quick one for you this time.
I want to strip the first and last character from a string.
What is the most efficient way to do this in BASIC?
Thanks for your help Daniel.
Robert
.
Re: How-to strip the first & last character from a string ??
Posted: Fri Mar 15, 2013 8:52 pm
by Daniel
Hi Robert
The easiest way is with the LEFT$, RIGHT$ and LEN functions. Lets call the string A$
Code: Select all
A$="abcdefghijklmnopqrstuvwxyz"
LenA = LEN( A$)
PRINT LenA
'Remove right most character
ShortA$ = LEFT$( A$, LenA-1)
PRINT ShortA$
EvenShorterA$= RIGHT$( ShortA$, LenA-2)
PRINT EvenShorterA$
END
If you run this program it will print
Code: Select all
26
abcdefghijklmnopqrstuvwxy
bcdefghijklmnopqrstuvwxy
Hope this is clear. There is also a MID$ function for breaking strings in pieces.
Daniel
Re: How-to strip the first & last character from a string ??
Posted: Sat Mar 16, 2013 11:36 am
by RBSe
Thanks Daniel,
That makes it clear and easy to understand...
Robert
.