Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 21:39 17 May 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : TRIM

Author Message
Teo1
Newbie

Joined: 06/05/2023
Location: Romania
Posts: 12
Posted: 08:57pm 01 May 2024
Copy link to clipboard 
Print this post

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
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5923
Posted: 09:05pm 01 May 2024
Copy link to clipboard 
Print this post

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
VK7JH
MMedit   MMBasic Help
 
Teo1
Newbie

Joined: 06/05/2023
Location: Romania
Posts: 12
Posted: 09:32pm 01 May 2024
Copy link to clipboard 
Print this post

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
 
NPHighview

Senior Member

Joined: 02/09/2020
Location: United States
Posts: 197
Posted: 03:32am 02 May 2024
Copy link to clipboard 
Print this post

Teo - you write English much better than any of us write Romanian!
Live in the Future. It's Just Starting Now!
 
Print this page


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

© JAQ Software 2024