[gradsusr] Changing a string to lowercase

Jeff Duda jeffduda319 at gmail.com
Wed Mar 22 20:10:44 EDT 2017


There is no explicit function that does this. You will have to write your
own. I suggest creating two 26-member arrays, one for each case, as follows:

lowercase.1 = 'a'
lowercase.2 = 'b'
lowercase.3 = 'c'
...
...
...
lowercase.26 = 'z'
uppercase.1 = "A"
uppercase.2 = "B"
uppercase.3 = "C"
...
...
...
uppercase.26 = "Z"

When converting case in your input string, you need to assign a number
associated with the location of that number in the above arrays. Ex: c = 3,
t = 20. Since you cannot substitute individual string elements, you'll have
to build up a new string using a loop, switching the specific positions you
want to switch. You'll have to create a swap array to do this. Something
like
swap.1 = 1
swap.2 = 0
swap.3 = 0
could work, and would tell the program to swap the case of only the first
element (character).

This is clearly pretty intense, so you may want to just build a shortcut if
you know there is a limit to the types of strings you want to replace. If
all you're doing is months, you can do something as simple as

if (inituppermonth = "JAN")
 initlowermonth = "Jan"
endif
if (inituppermonth = "FEB")
 initlowermonth = "Feb"
endif
if (inituppermonth = "MAR")
 initlowermonth = "Mar"
endif
...
...
...

Jeff Duda

On Wed, Mar 22, 2017 at 6:05 PM, Charlie Phillips <charliep127 at hotmail.com>
wrote:

> Hello grads users,
>
>
> I am trying to change part of a string to lowercase. Is there was any way
> to do this in Grads?
>
>
> Specifically, I am trying to change the month string from the "q time"
> command to begin with an uppercase letter only instead of having it all
> uppercase - ex: I want to change MAR to Mar.
>
>
> Here's a sample piece of code... obviously it's missing the conversion to
> lowercase.
>
>
> 'q time'
>
> inituppermonth=substr(result, 13, 1)
> initlowermonth=substr(result, 14, 2)
> 'define initmonth='%inituppermonth' '%initlowermonth
>
>
> Thank you!
>
>
>
> _______________________________________________
> gradsusr mailing list
> gradsusr at gradsusr.org
> http://gradsusr.org/mailman/listinfo/gradsusr
>
>


-- 
Jeff Duda
Post-doctoral research fellow
University of Oklahoma School of Meteorology
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20170322/f26cb8aa/attachment.html 


More information about the gradsusr mailing list