![]() |
How to manage part of a STRING? - Printable Version +- Forum (https://www.boriel.com/forum) +-- Forum: Compilers and Computer Languages (https://www.boriel.com/forum/forumdisplay.php?fid=12) +--- Forum: ZX Basic Compiler (https://www.boriel.com/forum/forumdisplay.php?fid=11) +---- Forum: How-To & Tutorials (https://www.boriel.com/forum/forumdisplay.php?fid=13) +---- Thread: How to manage part of a STRING? (/showthread.php?tid=836) |
How to manage part of a STRING? - LukeBord1 - 01-08-2018 In standard Basic, we have this example correctly working: Code: 10 LET a$="123456789012345678901234567890xy" ...but it doesn't seem to work in ZXB: Code: DIM test AS STRING Thoughts? Re: How to manage part of a STRING? - LukeBord1 - 01-09-2018 SOLVED by myself! :lol: While in standard Basic the strings starts the count from "1", the ZXB syntax is "zero-based". All works fine by simply shifting the TO values. Good... Re: How to manage part of a STRING? - boriel - 01-09-2018 Well done! :!: There's also another option, --string-base=1 to make the original BASIC code to work. Also for arrays, --array-base=1 Check command line options for more flags: <!-- m --><a class="postlink" href="http://boriel.com/wiki/en/index.php/ZX_BASIC:Zxb#Command_Line_Options">http://boriel.com/wiki/en/index.php/ZX_ ... ne_Options</a><!-- m --> Actually, for full compatibility with Sinclair BASIC, you can use --sinclair, which will enable the above plus --strict-boolean (boolean values always 0 or 1). By default ZX BASIC uses base 0 and boolean values 0 for FALSE, and ANY other as true, because this allows better optimizations and performance. Re: How to manage part of a STRING? - ShaunBebbers - 01-09-2019 Hello, I am looking at string manipulation, particularly in terms of deleting the last character from a string. My routine is as follows: Code: 3 PRINT "Enter your number"; n$; "c:\>_"; The clear keyboard buffer routing is as follows: Code: 1000 IF INKEY$<>"" THEN GO TO 1000:END IF And the "delete last character" routine is: Code: 2000 LET c$="": It's the "delete last character" routine that I'm having trouble with. the b$(0 TO LEN(b$)-1) isn't doing what I'm expecting, i.e., if the contents of b$ are: Code: 12345 I want c$ to be: Code: 1234 and therefore be passed back to the b$ string before returning. Many thanks for any help or advice. Regards, Shaun. Re: How to manage part of a STRING? - boriel - 02-07-2019 ShaunBebbers Wrote:Hello, Have you tried with Code: b$(0 TO LEN(b$) - 2) Since by default ZX Basic strings are 0-based (the standard in BASIC is 1-based, that is, starting from position 1), LEN(b$) - 1 is the position of the last character. So LEN(b$) - 2 is the 2nd to last. Try this and tell me, please. :roll: |