Jump to content

Recommended Posts

Posted (edited)

Well, I like creating random functions that I have use for and I decided these had some use to them. Enjoy.

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
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 by Mattraks
Posted

Heh, sweet. I find the first one kinda useless, but nice little UDF's. Keep up the good work :P

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.

Posted

Interesting. Could be used for analyzing password complexness....is that a word?

edit: spell check say no but

complexness

noun

the quality of being intricate and compounded;

  • Moderators
Posted

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.

Posted

Ahh... the power of Regular Expressions

Holy Makerel. You ain't kiddin! I knew reg expressions could do some pretty useful stuff. I better start learnin me some reg expr. :P Good stuff SmOke_N
Posted

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 :P
Posted (edited)

SmOke_N's StringGetLetters() have underscore issue. :P

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. :idea:

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 by spudw2k
  • Moderators
Posted

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 :P ...

SmOke_N's StringGetLetters() have underscore issue. :P

Nice catch :(

But this doesn't :idea:

Func StringGetLetters($s_string)
    Return StringRegExpReplace($s_string, "[^[:alpha:]]", "")
EndFunc
:P ... 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.

Posted (edited)

:( ... the ^ is redundant, but all the same :idea:

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 :P

Edited by spudw2k
Posted (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 by SwiftBurns

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
×
×
  • Create New...