Converting a String to Upper case.

General discussion on mikroBasic PRO for PIC32.
Post Reply
Author
Message
Skyfall
Posts: 32
Joined: 06 Aug 2017 16:31

Converting a String to Upper case.

#1 Post by Skyfall » 31 Jan 2020 19:45

Hi,

Looking to convert mixed Upper/lower case characters to Upper case. Not sure where to start. Any help would be appreciated!

Compiler is mikroBasic Pro for PIC32.

Dim TXdata as string[4]
TXdata = "Fred"

How do I make 'Fred' look like 'FRED'?

Thank you!

brandonb
Posts: 105
Joined: 24 Jan 2013 03:24

Re: Converting a String to Upper case.

#2 Post by brandonb » 02 Feb 2020 11:06

looking as ascii chart on web, you'll see 'A' = 65 and 'a' = 97.... the difference is 32. which means you can loop through the string until null is reached while checking each character to see if( (char >= 'a') && (char <= 'z') ) if true for current character subtract 32 which happens to be a ' ' character. this will upper case all characters in string but only if they are a lower case character from and including a-z.

Skyfall
Posts: 32
Joined: 06 Aug 2017 16:31

Re: Converting a String to Upper case.

#3 Post by Skyfall » 09 Feb 2020 14:59

Looks good!
Having trouble implementing it, though...

Thank you!

Skyfall
Posts: 32
Joined: 06 Aug 2017 16:31

Re: Converting a String to Upper case.

#4 Post by Skyfall » 14 Feb 2020 02:21

Struggling with the Mikrobasic statements to implement this function:

if( (char >= 'a') && (char <= 'z') ) if true subtract 32.
Not sure how to subtract a number from a string.

Does anyone have the code for this, or can suggest another way of converting a mixed Upper/lower case string to an uppercase string?

Thank you!

brandonb
Posts: 105
Joined: 24 Jan 2013 03:24

Re: Converting a String to Upper case.

#5 Post by brandonb » 14 Feb 2020 02:51

32 is also the the ascii space character which is ' ', will it let you subtract by ' ' ? sorry i don't know anything about basic

Skyfall
Posts: 32
Joined: 06 Aug 2017 16:31

Re: Converting a String to Upper case.

#6 Post by Skyfall » 16 Feb 2020 09:49

Thank you! :D

Skyfall
Posts: 32
Joined: 06 Aug 2017 16:31

Re: Converting a String to Upper case.

#7 Post by Skyfall » 18 Feb 2020 14:25

Issue solved:

Code becomes -

for i= 0 to length(textin)
if (textin >= 97) and (textin <= 122) then
textin= textin- 32
end if
next i


brandonb…Thanks again! :lol:

brandonb
Posts: 105
Joined: 24 Jan 2013 03:24

Re: Converting a String to Upper case.

#8 Post by brandonb » 20 Feb 2020 20:40

brandonb…Thanks again!
right on, thanks for the update

Post Reply

Return to “mikroBasic PRO for PIC32 General”