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

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

Postby RBSe » Fri Mar 15, 2013 7:27 pm

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

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

Postby Daniel » Fri Mar 15, 2013 8:52 pm

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
Daniel
 
Posts: 91
Joined: Tue Nov 13, 2012 2:10 pm

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

Postby RBSe » Sat Mar 16, 2013 11:36 am

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


Return to EzSBC1

Who is online

Users browsing this forum: No registered users and 1 guest

cron