Convert a string to upper case in BASIC?

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
User avatar
presuminged
Drutt
Posts: 11
Joined: Fri Dec 13, 2019 10:54 am
Location: Leeds
Contact:

Convert a string to upper case in BASIC?

Post by presuminged »

Can this be done?
Ralf
Rick Dangerous
Posts: 2285
Joined: Mon Nov 13, 2017 11:59 am
Location: Poland

Re: Convert a string to upper case in BASIC?

Post by Ralf »

There isn't any ready function like ToUpper to do it, I believe.

You can make it with your own code however. Loop through all characters in the string, check their ASCII value and if it is a lowercase letter change it to uppercase.
User avatar
g0blinish
Manic Miner
Posts: 284
Joined: Sun Jun 17, 2018 2:54 pm

Re: Convert a string to upper case in BASIC?

Post by g0blinish »

I bet it needs to improvement:

Code: Select all

  10 INPUT ">";A$
  11 LET b$=""
  20 FOR i=1 TO LEN (a$)
  21 LET b=CODE (a$(i))
  22 IF b>=97 AND b<=122 THEN LET b=b-32
  23 LET b$=b$+CHR$ (b-32)
  29 NEXT i
  30 PRINT b$
User avatar
jpnz
Manic Miner
Posts: 319
Joined: Tue Nov 14, 2017 4:07 pm
Location: Hamilt[r]on - City Of The Future - NZ

Re: Convert a string to upper case in BASIC?

Post by jpnz »

You could use a function - have a look at this article
User avatar
presuminged
Drutt
Posts: 11
Joined: Fri Dec 13, 2019 10:54 am
Location: Leeds
Contact:

Re: Convert a string to upper case in BASIC?

Post by presuminged »

Thanks for the replies!
Post Reply