Menu
JAQForum Ver 19.10.27

Forum Index : Microcontroller and PC projects : TRIM

Posted: 08:57pm
01 May 2024
Copy link to clipboard
Teo1
Newbie

Hi all,
From the manual :
S$ = " ****23.56700 "
PRINT Trim$(s$, " ")
I have the error :
"Error : TRIM is not declared"
What did I do wrong ?
Thanks in advance ,
Teo
 
Posted: 09:05pm
01 May 2024
Copy link to clipboard
TassyJim
Guru


Read the manual just before the example you are quoting
  Quote  There is often the need for a special command or function to be implemented in MMBasic but in many cases
these can be constructed using an ordinary subroutine or function which will then act exactly the same as a built
in command or function.
For example, sometimes there is a requirement for a TRIM function which will trim specified characters from
the start and end of a string. The following provides an example of how to construct such a simple function in
MMBasic.
The first argument to the function is the string to be trimmed and the second is a string containing the
characters to trim from the first string. RTrim$() will trim the specified characters from the end of the string,


 ' trim any characters in c$ from the start and end of s$
FUNCTION Trim$(s$, c$)
 Trim$ = RTrim$(LTrim$(s$, c$), c$)
END FUNCTION
 ' trim any characters in c$ from the end of s$
FUNCTION RTrim$(s$, c$)
 RTrim$ = s$
 DO WHILE INSTR(c$, RIGHT$(RTrim$, 1))
   RTrim$ = MID$(RTrim$, 1, LEN(RTrim$) - 1)
 LOOP
END FUNCTION
 ' trim any characters in c$ from the start of s$
FUNCTION LTrim$(s$, c$)
 LTrim$ = s$
 DO WHILE INSTR(c$, LEFT$(LTrim$, 1))
   LTrim$ = MID$(LTrim$, 2)
 LOOP
END FUNCTION


Jim
 
Posted: 09:32pm
01 May 2024
Copy link to clipboard
Teo1
Newbie

Jim, thanks a lot.
It's hard for me because English is not known to me and I'm just starting out with MMBASIC.
Teo
 
Posted: 03:32am
02 May 2024
Copy link to clipboard
NPHighview
Senior Member


Teo - you write English much better than any of us write Romanian!
 


To reply to this topic, you need to log in.

© JAQ Software 2024