|
Forum Index : Microcontroller and PC projects : Stripping leading space from PRINT?
| Author | Message | ||||
| BobC Newbie Joined: 10/06/2017 Location: United StatesPosts: 9 |
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: GermanyPosts: 1671 |
Hi, 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 causality ≠ correlation ≠ coincidence |
||||
| JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 4133 |
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 StatesPosts: 769 |
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: ThailandPosts: 2209 |
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. Microblocks. Build with logic. |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |