Mattraks Posted October 8, 2008 Share Posted October 8, 2008 (edited) Well, I like creating random functions that I have use for and I decided these had some use to them. Enjoy. expandcollapse popupFunc StringPercentCaps($sTempString) Local $aTempSplit = StringSplit(StringGetLetters($sTempString), ""), $iTempCap = 0, $iTempResult For $iTempOn = 1 To $aTempSplit[0] If StringIsUpper($aTempSplit[$iTempOn]) Then $iTempCap += 1 EndIf Next $iTempResult = Round(($iTempCap / StringLen(StringGetLetters($sTempString))) * 100, 0) Return $iTempResult EndFunc Func StringGetLetters($sTempString) Local $aTempSplit = StringSplit($sTempString, ""), $sTempNew For $iTempOn = 1 To $aTempSplit[0] If StringIsAlpha($aTempSplit[$iTempOn]) Then $sTempNew &= $aTempSplit[$iTempOn] EndIf Next Return $sTempNew EndFunc Func StringGetCapsNum($sTempString) Local $aTempSplit = StringSplit($sTempString, ""), $iTempCap = 0 For $iTempOn = 1 To $aTempSplit[0] If StringIsUpper($aTempSplit[$iTempOn]) Then $iTempCap += 1 EndIf Next Return $iTempCap EndFuncoÝ÷ ØLZ^jëh×6#NoTrayIcon $sString = "ThIs Is SpArTa 123 $@%" ConsoleWrite("The percentage of caps of the string: '" & $sString & "' is " & StringPercentCaps($sString) & @CRLF) ConsoleWrite("The letters in the string are: " & StringGetLetters($sString) & @CRLF) ConsoleWrite("The number of caps the string has is " & StringGetCapsNum($sString)) Func StringPercentCaps($sTempString) Local $aTempSplit = StringSplit(StringGetLetters($sTempString), ""), $iTempCap = 0, $iTempResult For $iTempOn = 1 To $aTempSplit[0] If StringIsUpper($aTempSplit[$iTempOn]) Then $iTempCap += 1 EndIf Next $iTempResult = Round(($iTempCap / StringLen(StringGetLetters($sTempString))) * 100, 0) Return $iTempResult EndFunc Func StringGetLetters($sTempString) Local $aTempSplit = StringSplit($sTempString, ""), $sTempNew For $iTempOn = 1 To $aTempSplit[0] If StringIsAlpha($aTempSplit[$iTempOn]) Then $sTempNew &= $aTempSplit[$iTempOn] EndIf Next Return $sTempNew EndFunc Func StringGetCapsNum($sTempString) Local $aTempSplit = StringSplit($sTempString, ""), $iTempCap = 0 For $iTempOn = 1 To $aTempSplit[0] If StringIsUpper($aTempSplit[$iTempOn]) Then $iTempCap += 1 EndIf Next Return $iTempCap EndFunc Edited October 8, 2008 by Mattraks Link to comment Share on other sites More sharing options...
TehWhale Posted October 8, 2008 Share Posted October 8, 2008 Heh, sweet. I find the first one kinda useless, but nice little UDF's. Keep up the good work Link to comment Share on other sites More sharing options...
Mattraks Posted October 8, 2008 Author Share Posted October 8, 2008 Heh, sweet. I find the first one kinda useless, but nice little UDF's. Keep up the good work Thanks, but why do you think its useless? I made these for my IRC Bot and felt they were useful for other things and thought I should post them. The StringPercentCaps is good for the IRC Bot so then I can kick when someone says something with too many caps. It could go with other things too i guess so its not completely useless. Link to comment Share on other sites More sharing options...
spudw2k Posted October 8, 2008 Share Posted October 8, 2008 Interesting. Could be used for analyzing password complexness....is that a word?edit: spell check say no butcomplexnessnounthe quality of being intricate and compounded; Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX BuilderMisc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retreive SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose ArrayProjects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalcCool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
BrettF Posted October 8, 2008 Share Posted October 8, 2008 Nice work! Nothing is useless... most of the time This is pretty useful, so good job! Keep it up! Cheers, Brett Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
Achilles Posted October 8, 2008 Share Posted October 8, 2008 Why not just have the StringPercentCaps call the StringGetCapsNum? Like this: Func StringPercentCaps($sTempString) Local $iTempCap = StringGetCapsNum($sTempString), $iTempResult $iTempResult = Round(($iTempCap / StringLen(StringGetLetters($sTempString))) * 100, 0) Return $iTempResult EndFunc My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list] Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted October 8, 2008 Moderators Share Posted October 8, 2008 Ahh... the power of Regular Expressions:$sString = "ThIs Is SpArTa 123 $@%" ConsoleWrite("The percentage of caps of the string: '" & $sString & "' is " & StringPercentCaps($sString) & @CRLF) ConsoleWrite("The letters in the string are: " & StringGetLetters($sString) & @CRLF) ConsoleWrite("The number of caps the string has is " & StringGetCapsNum($sString) & @CRLF) Func StringPercentCaps($s_string) Return Round((UBound(StringRegExp($s_string, "[[:upper:]]", 3)) / StringLen($s_string) * 100), 0) EndFunc Func StringGetLetters($s_string) Return StringRegExpReplace($s_string, "\d|\W", "") EndFunc Func StringGetCapsNum($s_string) Return UBound(StringRegExp($s_string, "[[:upper:]]", 3)) EndFunc Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
spudw2k Posted October 8, 2008 Share Posted October 8, 2008 Ahh... the power of Regular ExpressionsHoly Makerel. You ain't kiddin! I knew reg expressions could do some pretty useful stuff. I better start learnin me some reg expr. Good stuff SmOke_N Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX BuilderMisc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retreive SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose ArrayProjects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalcCool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
ludocus Posted October 8, 2008 Share Posted October 8, 2008 wow... SmOke_N... great.. I don't even know how to use StringRegExp.. Link to comment Share on other sites More sharing options...
Mattraks Posted October 8, 2008 Author Share Posted October 8, 2008 Ahh... the power of Regular Expressions:$sString = "ThIs Is SpArTa 123 $@%" ConsoleWrite("The percentage of caps of the string: '" & $sString & "' is " & StringPercentCaps($sString) & @CRLF) ConsoleWrite("The letters in the string are: " & StringGetLetters($sString) & @CRLF) ConsoleWrite("The number of caps the string has is " & StringGetCapsNum($sString) & @CRLF) Func StringPercentCaps($s_string) Return Round((UBound(StringRegExp($s_string, "[[:upper:]]", 3)) / StringLen($s_string) * 100), 0) EndFunc Func StringGetLetters($s_string) Return StringRegExpReplace($s_string, "\d|\W", "") EndFunc Func StringGetCapsNum($s_string) Return UBound(StringRegExp($s_string, "[[:upper:]]", 3)) EndFunc But my way works too Link to comment Share on other sites More sharing options...
Achilles Posted October 8, 2008 Share Posted October 8, 2008 But my way works too I haven't tested, but his is probably faster. Speed is important. Still, your udf's are good example scripts. And comparing them with Smoke_N's show how useful StringRegExp can be. My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list] Link to comment Share on other sites More sharing options...
trancexx Posted October 8, 2008 Share Posted October 8, 2008 But my way works too SmOke_N's StringGetLetters() have underscore issue. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
spudw2k Posted October 8, 2008 Share Posted October 8, 2008 (edited) SmOke_N's StringGetLetters() have underscore issue. But this doesn't Func StringGetLetters($s_string) Return StringRegExpReplace($s_string, "[^[:alpha:]]", "") EndFunc But my way works too Don't be discouraged Mattraks. I've had plenty of times when more advanced user here have written optimized versions of my code. Take it as a learning experience; if you share code here it's inevitably going to get some criticism, but not all bad. I haven't tested, but his is probably faster. Speed is important. Still, your udf's are good example scripts. And comparing them with Smoke_N's show how useful StringRegExp can be.After a little testing. here are my results. (using an Intel Core Duo2 Extreme X6800 2.93Ghz) String Length: 22 String Length: 66 String Length: 146 String Length: 404 edit: I also noticed that Mattraks' StringPercentCaps function only measures against letters returned from StringGetLetters. Trancexx's measures against the whole string. Edited October 9, 2008 by spudw2k Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX BuilderMisc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retreive SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose ArrayProjects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalcCool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted October 8, 2008 Moderators Share Posted October 8, 2008 But my way works too Don't be discouraged, I wasn't raining on your parade, just showing a more efficient/faster method that may come in handy for you in the future. You made an effort, and it's probably better than a lot could do on this forum ... SmOke_N's StringGetLetters() have underscore issue. Nice catch But this doesn't Func StringGetLetters($s_string) Return StringRegExpReplace($s_string, "[^[:alpha:]]", "") EndFunc ... the ^ is redundant, but all the same Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
spudw2k Posted October 9, 2008 Share Posted October 9, 2008 (edited) ... the ^ is redundant, but all the same But doesn't removing the ^ cause it to replace alpha chars with "" ? Is there a more appropriate way to write it? That was my firt time using any sort or reg expr...thanks to you.edit: guess not Edited November 6, 2008 by spudw2k Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX BuilderMisc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retreive SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose ArrayProjects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalcCool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
TehWhale Posted October 9, 2008 Share Posted October 9, 2008 (edited) @SmOke_N How long did it take you to learn the StringRegExp or StringRegExpReplace? I'm tring to learn these functions because they can but used for a lot of stuff, but they just seem really hard write now. Regards, Swift Edited October 9, 2008 by SwiftBurns Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now