UPPER / LOWER STRING

Hi All

I have written a script to upper or lower a string. It might not be useful by its own so you might want to integrate the script into an existing script whereby you want the output to be displayed on Upper / Lower case.
I will only post the UPPER script since it uses the same concept as the lower however, if anyone faces any issue to convert the Upper to the Lower Script do not hesitate to post.

I also have a script to Upper the first char of the string, i did not post but as i said it is the same concept.

Use if Useful and enjoy :sunglasses: :sunglasses: :sunglasses:

WRITTEN BY TSOKOTSA 2015©

This Script Was designed to check the CPU load every 10 minutes and SMS Notification in case the LOAD is Above certain Values.

:log info "STARTING upper to Lower";

Bellow is the string that will be converted. obviously on most cases you will get a val to convert

:local test ("convert to upper");

Here i define all possible chars in array in Upper and Lower cases

:local low ("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");
:local upp ("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");

:local result;
:local new;

I loop trough the string then compare each char with the elements on the low array. if match is found, then i get the

correspondent element on the Upp array.

With that said, meaning that the position of the elements of both arrays must be the same

:for i from=0 to=([:len $test] - 1) do={
:local char [:pick $test $i];

:if ($char = " ") do={
:set $char " ";
:set $new ($new . $char)
}

:for a from=0 to=([:len $low] - 1) do={

:local l [:pick $low $a];


:if ( $char = $l) do={
:local u [:pick $upp $a];
:log error "The UPPER of $char is $u";
:set new ($new .$u);
}

}

}

:log error "The New String in Upper case is: $new";

Ops, !!! please ignore the second comment on my script regarding the CPU load, that comment was copied from another script that i have written that checks the CPU load.

Thanks for the script, it has one issue others chars than in $low will be stripped except space char as you’re checking that in the script, so a quick fix will be
instead of this char space check

:if ($char = " ") do={
:set $char " ";
:set $new ($new . $char)
}

replace with this

:local f [:find "$low" "$char"];
:if ( $f < 0 ) do={
:set new ($new . $char);
}

This is a small workaround to the current scripting string limitation(for the moment i hope :slight_smile:) that we can’t change specified chars in strings.

Hi all,

I saw this and decided to re-write it, to be used as a function.
I used proper arrays so the reference could be indexed instead with the index call ($array->$index)

To call it simply reference the function in your code and call it:

:local replace [:parse [:system script get replace-upper-lower source]]
[$replace "convert me to upper" ] or [$replace "CONVERT ME TO LOWER" 1 ]

Just call this script ‘replace-upper-lower’

:local lower [:toarray "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z"]
:local upper [:toarray "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z"]
# Pass as param 2 to toggle conversion
:local mode false
:local result
:if (($2 = "") || ($2 = nil)) do={:set $mode true}
:for idx from=0 to=([:len $1] - 1) do={ 
	:local char [:pick $1 $idx]
	:local match
	:if ($mode) do={
		:for i from=0 to=[:len $lower] do={
			:set $match ($lower->$i)
			:if ($char = $match) do={:set $char ($upper->$i)}
		}
	} else={
		:for i from=0 to=[:len $upper] do={
			:set $match ($upper->$i)
			:if ($char = $match) do={:set $char ($lower->$i)}
		}
	}
	:set $result ($result.$char)
}
:return $result