Community discussions

MikroTik App
 
vitorlins
just joined
Topic Author
Posts: 8
Joined: Tue Apr 14, 2015 7:48 pm

Script to convert case uppercase lowercase

Wed Apr 29, 2015 10:10 pm

Hi, this script convert the case of a word.

Just run it on the terminal and this will add a scheduler to automatic active them when the router startup.

Usage:
[user@server] > :put [$toupper "www.goonet.com.br"] 
WWW.GOONET.COM.BR
[user@server] > :put [$tolower "WwW.GooNeT.CoM.Br"] 
www.goonet.com.br

Code:
{
/system scheduler add name=goonet.strcase on-event="{\r\
    \n:global strcase do={\r\
    \n\t:local toreplaceL {\"A\"=\"a\";\"B\"=\"b\";\"C\"=\"c\";\"D\"=\"d\";\"E\"=\"e\";\"F\"=\"f\";\"G\"=\"g\";\"H\"=\"h\";\"I\"=\"i\";\"J\"=\"j\";\"K\"=\"k\";\"L\"=\"l\";\
    \"M\"=\"m\";\"N\"=\"n\";\"O\"=\"o\";\"P\"=\"p\";\"Q\"=\"q\";\"R\"=\"r\";\"S\"=\"s\";\"T\"=\"t\";\"U\"=\"u\";\"V\"=\"v\";\"X\"=\"x\";\"Z\"=\"z\";\"Y\"=\"y\";\"W\"=\"w\"\
    };\r\
    \n\t:local toreplaceU {\"a\"=\"A\";\"b\"=\"B\";\"c\"=\"C\";\"d\"=\"D\";\"e\"=\"E\";\"f\"=\"F\";\"g\"=\"G\";\"h\"=\"H\";\"i\"=\"I\";\"j\"=\"J\";\"k\"=\"K\";\"l\"=\"L\";\
    \"m\"=\"M\";\"n\"=\"N\";\"o\"=\"O\";\"p\"=\"P\";\"q\"=\"Q\";\"r\"=\"R\";\"s\"=\"S\";\"t\"=\"T\";\"u\"=\"U\";\"v\"=\"V\";\"x\"=\"X\";\"z\"=\"Z\";\"y\"=\"Y\";\"w\"=\"W\"\
    };\r\
    \n\t:local toreplace \$toreplaceL;\r\
    \n\t:local str \$1;\r\
    \n\t:local newStr;\r\
    \n\t:local newChar;\r\
    \n\r\
    \n\t:if (\$2 = \"-u\") do={\r\
    \n\t\t:set toreplace \$toreplaceU;\r\
    \n\t}\r\
    \n\r\
    \n\t:for i from=0 to=([:len \$str] - 1) do={\r\
    \n\t  :local char [:pick \$str \$i];\r\
    \n\t  :set newChar (\$toreplace->\$char);\r\
    \n\t  \r\
    \n\t  :if ([:typeof \$newChar] = \"str\") do={\r\
    \n\t\t:set char \$newChar;\r\
    \n\t  }\r\
    \n\t  :set newStr (\$newStr . \$char);\r\
    \n\t}\r\
    \n\t:return \$newStr;\r\
    \n}\r\
    \n\r\
    \n:global tolower do={ :global strcase; return [\$strcase \$1]};\r\
    \n:global toupper do={ :global strcase; return [\$strcase \$1 -u]}\r\
    \n}" policy=read,write,policy,test start-time=startup
}
 
wgrando1993
just joined
Posts: 11
Joined: Tue Oct 25, 2016 3:45 pm

Re: Script to convert case uppercase lowercase

Thu Nov 16, 2017 9:09 pm

Hello guy, tks, help-me a lot, for complete an other script. hehehe.