Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 13:32 20 Sep 2026 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 : Stripping leading space from PRINT?

Author Message
BobC
Newbie

Joined: 10/06/2017
Location: United States
Posts: 9
Posted: 04:08pm 07 Feb 2019
Copy link to clipboard 
Print this post

I have a plotting app (Stamp Plot) that plots serial data sent from a micro ( MM in this case ). It wants a string consisting of numeric values ( numbers ) terminated with a 0x0d CR.

I'm not plotting data because I believe it does not like the leading space sent in a print statement. Error message I'm getting is Bad Data ASCII value <13 or >127.
I suspect it is because of the leading space.

Any way to strip this space out and print only numeric values? I tried ABS but still got the leading space.

Any ideas welcome!

Thanks!
Bob
GA USA
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1772
Posted: 04:46pm 07 Feb 2019
Copy link to clipboard 
Print this post

Hi,

  BobC said   I'm not plotting data because I believe it does not like the leading space sent in a print statement. Error message I'm getting is Bad Data ASCII value <13 or >127. I suspect it is because of the leading space.

I doubt that! Space is ASCII 32.

For the unwanted leading spaces you can use this code

'
'Remove leading Spaces from string
'
Function LTrim$(X$)
Local I,Z$ Length Len(X$)

'Make copy of caller's string so that we don't damage it
Z$=X$

For I=1 To Len(Z$)

'Find first NON-Space character
If Mid$(Z$,I,1)<>" " Then
Z$=Mid$(Z$,I)
Exit For
EndIf

Next I

LTrim$=Z$

End Function


'
' Remove trailing Spaces from string
' Peters rTrim, modified by twofingers
'
Function RTrim$(X$)
Local I

For I=Len(X$) To 1 Step -1
'Find first NON-Space character
If Mid$(X$,I,1)<>" " Then
Exit For ' be careful with Exit For
EndIf
Next I

RTrim$=Mid$(X$,1,I)

End Function


'
'Remove spaces from LHS and RHS of string
'
Function Trim$(X$)
Local Y$ length Len(X$)

'MMBasic doesn't like Trim$=RTrim$(LTrim$(X$))

Y$=LTrim$(X$)
Trim$=RTrim$(Y$)

End Function


and for the MM2 as CFunction this
https://www.thebackshed.com/forum/forum_posts.asp?TID=9738
Regards
Michael


Edited by twofingers 2019-02-09
‚My name is Ozymandias, king of kings
Look on my works, ye Mighty, and despair!‘
Nothing beside remains. Round the decay
Of that colossal wreck, boundless and bare
The lone and ...
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4380
Posted: 07:08pm 07 Feb 2019
Copy link to clipboard 
Print this post

Show us the part of code doing the PRINT :)

Maybe you're using something like
PRINT n

when what you want is more like
PRINT STR$(n)+CHR$(13);

John
 
Paul_L
Guru

Joined: 03/03/2016
Location: United States
Posts: 769
Posted: 06:33am 09 Feb 2019
Copy link to clipboard 
Print this post

The print routine is finding an unprintable character in the string you are handing it. (ASCII value <13 or >127). Print out the ASCII value of each character in the target string, PR$, like this.

for i=1 to len(PR$)
print asc( mid$(PR$,i,1) ),
next i

Inspect the results looking for something <13 or >127.

Paul in NY
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 09:00pm 09 Feb 2019
Copy link to clipboard 
Print this post

Check if the print statement is outputting a 0x0D0x0A pair (carriage return & linefeed) which is the standard with dos/windows.
A 0x0A (dec 10) is lower then the 0x0D (dec 13) of a carriage return.

If the output is parsed with a 0x0D on the end then the next character would be the 0x0A giving you a wrong first character.


Example two numbers 567 and 568


5670x0D0x0A5680x0D0x0A


The first parsed value delimited by a 0x0D wil be 567, the second vanlue will be 0x0A568 which will have an invalid first character.

Edited by MicroBlocks 2019-02-11
Microblocks. Build with logic.
 
Print this page


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

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2026