How-to strip the first & last character from a string ???

User avatar
RBSe
Posts: 33
Joined: Wed Mar 06, 2013 7:42 pm
Location: Eureka, California
Contact:

How-to strip the first & last character from a string ???

Unread post 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
.
Data is not information, information is not knowledge, knowledge is not understanding, understanding is not wisdom.

Clifford Stoll
Daniel
Posts: 133
Joined: Tue Nov 13, 2012 2:10 pm

Re: How-to strip the first & last character from a string ??

Unread post 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
User avatar
RBSe
Posts: 33
Joined: Wed Mar 06, 2013 7:42 pm
Location: Eureka, California
Contact:

Re: How-to strip the first & last character from a string ??

Unread post by RBSe »

Thanks Daniel,

That makes it clear and easy to understand... :D

Robert
.
Data is not information, information is not knowledge, knowledge is not understanding, understanding is not wisdom.

Clifford Stoll
Post Reply