# MSX Basic Question

Page 1/2
| 2

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'

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

```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\$```

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

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

Thanks guys! I think the solution provided by Nyyrikki will suit my needs

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....

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

Thx, ricbit, I now made this ```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\$```

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: !

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 ```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\$
```
Page 1/2
| 2