MSX Basic Question

Página 1/2
| 2

Por Mafcase

Champion (258)

Imagen del Mafcase

22-06-2017, 18:35

Does someone know how to strip/delete spaces in a string?

When I do this:
A=1: A$=STR$(A): print A$

The ouput is:
' 1' and I would like it to be '1'

Login sesión o register para postear comentarios

Por Wlcracks

Hero (565)

Imagen del Wlcracks

22-06-2017, 19:07

right$(a$,1)
or right$(a$,len(A$)-1)
or mid$(a$,2,len(a$)-1)
something like that?

Por Latok

msx guru (3938)

Imagen del Latok

22-06-2017, 19:08

10 a$="Anne is een boerenpummel"
20 fori=1tolen(a$)
30 b$=mid$(A$,i,1)
40 ifb$=chr$(32)thennexti
50 c$=c$+b$
60 nexti
70 print c$

Por NYYRIKKI

Enlighted (6067)

Imagen del NYYRIKKI

22-06-2017, 19:38

In this particular case:
A=1: A$=HEX$(A): print A$

... or:
A=1: print using "#";A

Por Mafcase

Champion (258)

Imagen del Mafcase

22-06-2017, 21:45

Thanks guys! Smile

I think the solution provided by Nyyrikki will suit my needs

Por Latok

msx guru (3938)

Imagen del Latok

22-06-2017, 21:59

Hm, in my listing, until now the only given solution to your generic question how to 'delete spaces from a string', if the last character in a$ is a space, the program will return a NEXT without FOR. So uhm:

10 a$="Anne is een enorme boerenpummel "
20 fori=1tolen(a$)
30 b$=mid$(A$,i,1)
40 ifb$=chr$(32)thengoto60
50 c$=c$+b$
60 nexti
70 print c$

Better....

Por ricbit

Champion (438)

Imagen del ricbit

22-06-2017, 22:07

You can optimize that by using INSTR to find the next space.

Por Latok

msx guru (3938)

Imagen del Latok

22-06-2017, 22:46

Thx, ricbit, I now made this Smile

10 a$="MSX no BASIC wa Commodore no BASIC yori omoshiroi desu yo "
20 fori=1tolen(a$)
30 a=instr(mid$(a$,i,1)," "):ifa=0thenb$=b$+mid$(a$,i,1)
40 nexti
50 printb$

Por Manuel

Ascended (19465)

Imagen del Manuel

23-06-2017, 00:02

Latok, you can do better! INSTR gives you the position of the first space! So no need to loop over all characters! See https://www.msx.org/wiki/INSTR

PS: !

Por Latok

msx guru (3938)

Imagen del Latok

23-06-2017, 09:31

Haha, I love this.... Thanks for the push, Manuel ^__^ No need to loop over all the characters? Had to think about it, honestly, but just came up with this:

10 b=1:d=0:a$="manuel-san wa ichiban ookii hito desu"
20 a=instr(b,a$," "):ifa=0thengoto40
30 c=a-d-1:b$=b$+mid$(a$,b,c):b=a+1:d=a:goto20
40 printb$

It does the job, but I needed 4 variables to make it work. I don't think it's very elegant coding... Enlighten me, Manuel, show me something beautiful Smile

Por chalky

Expert (67)

Imagen del chalky

24-06-2017, 00:50

10 A$="manuel-san wa ichiban ookii hito desu"
20 A=INSTR(A$," "):IFA=0THENGOTO40
30 A$=LEFT$(A$,A-1)+MID$(A$,A+1):GOTO20
40 PRINTA$
Página 1/2
| 2