MSX Basic Question

Страница 1/2
| 2

By Mafcase

Master (231)

Аватар пользователя 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

By Wlcracks

Champion (321)

Аватар пользователя 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?

By Latok

msx guru (3671)

Аватар пользователя 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$

By NYYRIKKI

Enlighted (5356)

Аватар пользователя NYYRIKKI

22-06-2017, 19:38

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

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

By Mafcase

Master (231)

Аватар пользователя Mafcase

22-06-2017, 21:45

Thanks guys! Smile

I think the solution provided by Nyyrikki will suit my needs

By Latok

msx guru (3671)

Аватар пользователя 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....

By ricbit

Champion (437)

Аватар пользователя ricbit

22-06-2017, 22:07

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

By Latok

msx guru (3671)

Аватар пользователя 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$

By Manuel

Ascended (15680)

Аватар пользователя 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: !

By Latok

msx guru (3671)

Аватар пользователя 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

By chalky

Resident (39)

Аватар пользователя 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$
Страница 1/2
| 2