Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Changing case of a string
#1
Hi Gintaras,

Nice easy one (even though I cant see a straight answer anywhere, If i have a simple string, how do i change it from "quick macros" to "QUICK MACROS"?

i.e changing everything to uppercase whether they were originally or not.
#2
Macro Macro2
Code:
Copy      Help
;; ------ CONVERT TO UPPERCASE
str sa="abc"
int i
for i 0 sa.len ;; Iterate through each letter, first 'a' then 'b' then 'c', but now we iterate trough each corresponding character code (QM HELP > chapter 'character codes')
,sa[i]=toupper(sa[i]) ;; Current letter in character code format transformed to UPPERCASE.
out sa ;; each letter from string 'sa' has been transformed to uppercase,  output should be: 'ABC'
;; you can change 'toupper' to 'tolower' to convert to lowercase


;; ------ INVERT CASE
;; If you understand above code then you should be able to figure out below code
str sb="xYz"
for i 0 sb.len
,if(isupper(sb[i]))
,,sb[i]=tolower(sb[i])
,else
,,sb[i]=toupper(sb[i])
out sb ;; should output 'XyZ'


Forum Jump:


Users browsing this thread: 1 Guest(s)