Jump to content
Sign in to follow this  
benzrf

_lcase & _ucase & _changecase

Recommended Posts

benzrf

In pretty much every programming language I've ever seen, there was a lcase() and ucase() function. However, I looked through the helpfile and quickly realized that neither of these exist in AutoIt. So I adapted a script I'd written before, and this is the result.

CODE

Func _lcase($a)

For $i = 1 to StringLen($a)

$b = StringMid($a, $i, 1)

If Asc($^_^ >= 97 And Asc($;) <= 122 Then

$c = $c & Chr(Asc($:( - 32)

Else

$c = $c & $b

EndIf

Next

Return $c

EndFunc

Func _ucase($a)

For $i = 1 to StringLen($a)

$b = StringMid($a, $i, 1)

If Asc($:D >= 65 And Asc($:D <= 90 Then

$c = $c & Chr(Asc($:) + 32)

Else

$c = $c & $b

EndIf

Next

Return $c

EndFunc

Func _changecase($a)

For $i = 1 to StringLen($a)

$b = StringMid($a, $i, 1)

If Asc($:P >= 97 And Asc($;) <= 122 Then

$c = $c & Chr(Asc($B) - 32)

ElseIf Asc($B) >= 65 And Asc($B) <= 90 Then

$c = $c & Chr(Asc($B) + 32)

Else

$c = $c & $b

EndIf

Next

Return $c

EndFunc

By the way, in the unlikely event that you both couldn't guess and couldn't tell from the code, _changecase() makes uppercase letters lowercase and lowercase, uppercase.

Share this post


Link to post
Share on other sites
zackrspv

Just a note, StringUpper and StringLower per the help file ^_^

But nonetheless good job making your own ;)


-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Share this post


Link to post
Share on other sites
gseller

Very Nice to make your own. Here is my take, just for another look at it...

;http://www.autoitscript.com/forum/index.php?s=&showtopic=54412&view=findpost&p=413683
#NoTrayIcon
#include <GUIConstants.au3>
#Include <String.au3>
#Include <GuiEdit.au3>

;Global Const $ES_MULTILINE = 4
;Global Const $ES_AUTOVSCROLL = 64
Global Const $WS_VSCROLL = 0x00200000


$AForm1 = GUICreate("Alpha/Numeric Manipulator", 375, 175, 193, 125)
$Input1=GUICtrlCreateEdit("",10,7,357,105,BitOR($ES_MULTILINE,$ES_AUTOVSCROLL,$WS_VSCROLL))
$Combo = GUICtrlCreateCombo("Select", 7, 140, 75, 25)
GUICtrlSetData($Combo, "#Crunch|Reset|UPPER CASE|lower case|Proper Case|Reverse|Binary|Binary2str|chr2ASCII|ASCII2chr|Unicode|Dec2Hex|Hex2Dec", "")
$Btn_Go = GUICtrlCreateButton("Undo",95, 140, 75, 25)
$dummy = ""
$dummy2 = ""
GUISetState(@SW_SHOW)

While 1
   $nMsg = GUIGetMsg()
   $bOut = GUICtrlRead($Combo)
   If StringInStr($bOut, "#") Then $bOut = StringReplace($bOut, "#", "")
   If StringInStr($bOut, " case") Then $bOut = StringReplace($bOut, " case", "")
   Switch $nMsg
      Case $GUI_EVENT_CLOSE
         Exit
     Case $Combo
         $dummy = GUICtrlRead($Input1)
         GUICtrlSetData($Input1,SetCase($bOut))
        Case $Btn_Go
         $dummy2 = GUICtrlRead($Input1)
         GUICtrlSetData($Input1, $dummy)
         $dummy = $dummy2
   EndSwitch
Wend


Func SetCase($sCaseType)
Local $r = GUICtrlRead($Input1), $o

Switch $sCaseType
  Case "Upper"
   $o = StringUpper($r)
  Case "Lower"
   $o = StringLower($r)
  Case "Crunch"
   $o = StringRegExpReplace(($r), "[^0-9]", "")
  Case "Reset"
   $o = StringRegExpReplace(($r), "[^ ]", "")
  Case "Proper"
   $o = _StringProper($r)
  Case "Reverse"
   $o = _StringReverse($r)
  Case "chr2ASCII"
   $o = Asc($r)
  Case "ASCII2chr"
   $o = Chr($r)   
  Case "Binary"
   $o = StringToBinary($r)
  Case "Binary2str"
   $o = BinaryToString($r)   
  Case "Unicode"
   $o = AscW($r)
  Case "Dec2Hex"
   $o = Hex($r)   
  Case "Hex2Dec"
   $o = Dec($r)   
EndSwitch
  Return $o
EndFunc

Share this post


Link to post
Share on other sites
TheSaint

In pretty much every programming language I've ever seen, there was a lcase() and ucase() function. However, I looked through the helpfile and quickly realized that neither of these exist in AutoIt. So I adapted a script I'd written before, and this is the result.

It's always nice to see someone else's take on something, but obviously you don't know how to search the help file or forum ... and you missed my topic, last updated 4 days ago (here), which could have also pointed you in the right direction. ^_^

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites
gseller

TheSaint' s functions work very well in my example. I like the way it works with roman numerals and something like McBeth and such.. Good Job!

Share this post


Link to post
Share on other sites
TheSaint

TheSaint' s functions work very well in my example. I like the way it works with roman numerals and something like McBeth and such.. Good Job!

Thanks!

Some of my programs also have a toggle case function, which toggles between what I call the five cases - lower, upper, proper (or title), sentence, original ... of course you could probably add iCase to that these days (second letter uppercase).


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites
gseller

Thanks!

Some of my programs also have a toggle case function, which toggles between what I call the five cases - lower, upper, proper (or title), sentence, original ... of course you could probably add iCase to that these days (second letter uppercase).

Very intuitive scripting! ^_^

Share this post


Link to post
Share on other sites
TheSaint

Very intuitive scripting! ^_^

Well I do try to please .... even if it's only myself most of the time, and I figure, that if I'm pleased, someone somewhere else will be also. ;)

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites
gseller

Well I do try to please .... even if it's only myself most of the time, and I figure, that if I'm pleased, someone somewhere else will be also. ^_^

I for one have learned alot from your examples!

Share this post


Link to post
Share on other sites
TheSaint

I for one have learned alot from your examples!

That's nice to hear, and one of the reasons I share! ^_^

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×