I am not aware that gnuplot offers uppercase or lowercase functions.
The attempt below is not a function but a macro which converts the string variable w into uppercase or lowercase without external tools as desired from the OP. Characters which are not found in the list are kept unchanged. There is probably room for improvement, but maybe it will still be helpful to somebody.
### gnuplot implementation of uppercase and lowercase
reset session
Cases= "ABCDEFGHIJKLMNOPQRSTUVWXYZ".\
"abcdefghijklmnopqrstuvwxyz"
uppercase = 'CaseLen=strlen(Cases)/2;\
wc = ""; \
do for [i=1:strlen(w)] { \
tmp1 = substr(w,i,i); \
tmp2 = strstrt(Cases,tmp1); \
wc = (tmp2 == 0) ? wc = wc.tmp1 : \
(tmp2 > CaseLen) ? (tmp2=tmp2-CaseLen, \
wc.substr(Cases,tmp2,tmp2)) : wc.substr(Cases,tmp2,tmp2);\
}; w = wc'
lowercase = 'CaseLen=strlen(Cases)/2;\
wc = ""; \
do for [i=1:strlen(w)] { \
tmp1 = substr(w,i,i); \
tmp2 = strstrt(Cases,tmp1); \
wc = (tmp2 == 0) ? wc.tmp1 : \
(tmp2 < CaseLen) ? (tmp2=tmp2+CaseLen, \
wc.substr(Cases,tmp2,tmp2)) : wc.substr(Cases,tmp2,tmp2);\
}; w = wc'
# put your string into variable w
w = "...thE qUick brOWn foX jUmPs oVeR The LazY Dog!"
print w
# run the macro uppercase and variable w will we converted to uppercase
@uppercase
print w
# run the macro lowercase and variable w will we converted to lowercase
@lowercase
print w
### end of code
Output:
...thE qUick brOWn foX jUmPs oVeR The LazY Dog!
...THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG!
...the quick brown fox jumps over the lazy dog!
Addition: improved version
I guess that's the spirit of SO... together find the best solutions :-).
@mjp, using your nice idea about adding the character at the end and my "new" idea of "misusing" the summation expression sum as a loop, thus avoiding recursion. The follwing solution does not have the limit of 247 characters for the string which the recursive solution has (at least on my computer it was 247). I hope there will be no severe limitations in this solution.
### gnuplot implementation of uppercase and lowercase
# theozh, 14.01.2019
reset session
UpperCases= "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
LowerCases= "abcdefghijklmnopqrstuvwxyz"
# upper/lowercase for characters
ucchar(c) = substr( UpperCases.c, ucchar_tmp=strstrt(LowerCases.c, c), ucchar_tmp)
lcchar(c) = substr( LowerCases.c, lcchar_tmp=strstrt(UpperCases.c, c), lcchar_tmp)
# upper/lowercase for strings
uc(s) = ((sum[uc_i=1:strlen(s)] (uc_tmp=ucchar(substr(s,uc_i,uc_i)), uc_i>1 ? (uc_w=uc_w.uc_tmp,1):uc_w=uc_tmp,1)),uc_w)
lc(s) = ((sum[lc_i=1:strlen(s)] (lc_tmp=lcchar(substr(s,lc_i,lc_i)), lc_i>1 ? (lc_w=lc_w.lc_tmp,1):lc_w=lc_tmp,1)),lc_w)
s = "...thE qUick brOWn foX jUmPs oVeR The LazY Dog!"
print s
print uc(s)
print lc(s)
### end of code
Edit: (Jan. 2022)
I stumbled again over my old post and thought it can be further simplified. And more characters are added to the lookup strings.
Code:
### uppercase/lowercase function for gnuplot
reset session
UpperCases= "ABCDEFGHIJKLMNOPQRSTUVWXYZÄÁÂÀËÉÊÈÏÍÎÌÖÓÔÒÜÚÛÙŸÝ"
LowerCases= "abcdefghijklmnopqrstuvwxyzäáâàëéêèïíîìöóôòüúûùÿý"
# upper/lowercase for characters
ucc(c) = ((ucc_i=strstrt(LowerCases, c)) ? UpperCases[ucc_i:ucc_i] : c)
lcc(c) = ((lcc_i=strstrt(UpperCases, c)) ? LowerCases[lcc_i:lcc_i] : c)
# upper/lowercase for strings
uc(s) = (uc_s='', sum[uc_i=1:strlen(s)] (uc_s=uc_s.ucc(s[uc_i:uc_i]),1),uc_s)
lc(s) = (lc_s='', sum[lc_i=1:strlen(s)] (lc_s=lc_s.lcc(s[lc_i:lc_i]),1),lc_s)
s = "...thE qUick brOWn foX jUmPs oVeR The LazY Dog!"
print "Input: ", s
print "Uppercase: ", uc(s)
print "Lowercase: ", lc(s)
### end of code
Result:
Input: ...thE qUick brOWn foX jUmPs oVeR The LazY Dog!
Uppercase: ...THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG!
Lowercase: ...the quick brown fox jumps over the lazy dog!
awkis not capable to upper/lower non-ASCII letters. Are you trying to check if a string contains a substring in Bash? - Wiktor Stribiżewif [[ ${ARG2,,} == "ohms" ]]; then echo YES; fi- Wiktor Stribiżewarg2=system("${ARG2,,}")- Wiktor Stribiżewif [[ ${ARG2,,} == "ohms" ]]; then echo YES; fiseems to not be gnuplot syntax - I get an error message - expecting expression. - mjp