Jump to content
Sign in to follow this  
Jeep

[UDF] Some more string management routines

Recommended Posts

Here is an other UDF for string handling :

Date handling

_StringDateConvert:  convert a date from one format ("YMD", "MDY" or "DMY") to another.

_StringIsDate:  checks if a date with a given format is valid

String management

_StringCount: count of occurrences that appear in a string

_StringFormatBytesSize: formatting a dimension expressed in bytes (bytes) in MB, TB, ...)

_StringIsEndingWith: check if a string end with some characters

_StringIsStartingWith: check if a string start with some characters

_StringJoinArray:  concatenate elements of an array to rebuild a string

_StringPadLeft: filling a string with characters on the left

_StringPadRight: fill a string with characters on the right

_StringRemoveFrenchAccent: remove french accent

_StringRemoveChars: deleting characters from a string

_StringStrip: eliminate characters at the begin and/or at the  end of a string

_StringTitleCaseFrench: capitalize the first letter of each word with elimination of french accents

_StringWSClean: simple replacement of "White Spaces",  remove beginning and trailing spaces and multiple spaces removal

Any comments, suggestions for improvement or constructive criticism are welcome.

Below you will find the UDF and a demo program. 

 

 

JPD_String.zip

Edited by Jeep
Unvaluable fonction has been removed

Share this post


Link to post
Share on other sites

This is awesome... I like the encryption part... what standard is the encryption method? AES 128, 192 or 256 bits?

Edited by Skeletor

Kind Regards
Skeletor

"I need coffee to turn me back to a human"

Microsoft Office Splash Screen | Basic Notepad Program (Beginner) | Transparent Splash Screen

Share this post


Link to post
Share on other sites

Dear Skeletor,

Encryption method are one of the method supported by _Crypt_EncryptData (see _Crypt_DeriveKey : creates a key from algorithm and password) :

The constants are defined in "#include <Crypt.au3>"

$CALG_AES_128     128 bits
$CALG_AES_192     192 bits
$CALG_AES_256        256 bits
$CALG_DES     56 bits
$CALG_3DES     168 bits
$CALG_RC2     128 bits
$CALG_RC4     128 bits

You may use these  constants as the value supplied for $iAlgorithm parameter in StringEncrypt and StringDecrypt. The default is $CALG_RC4. Use the same value in the two functions if you would like to receive the correct result :-).

Edited by Jeep

Share this post


Link to post
Share on other sites

Dear Jeep,

So basically your UDF's just point back to the original code.. I see it in you MsgBox ... you just wrapped a Func around it. 
 


Kind Regards
Skeletor

"I need coffee to turn me back to a human"

Microsoft Office Splash Screen | Basic Notepad Program (Beginner) | Transparent Splash Screen

Share this post


Link to post
Share on other sites

Hello Skeletor, 

That's exactly what the function do: simplify the use of basic function already implemented in AutoIt. I've  spend few hours playing with all the basic Crypt functions and it's my result how to do simply the job.

 

 

Share this post


Link to post
Share on other sites
3 hours ago, Jeep said:

Hello Skeletor, 

That's exactly what the function do: simplify the use of basic function already implemented in AutoIt. 

Care to expand on this? I guess I am wondering at why someone would use your _StringBetween2 function, for example, when there is already a _StringBetween (as noted yourself in your comments). What does your function do that the native function does not? Same with _StringAppend, you take a one-line snippet and expand it into a whole function - is there really a need to pad it like that?

I'm all for new folks learning the language and trying new things, but the Examples forum is intended to be a showcase for "cool scripts". If what you are doing is simply adding another wrapper around an existing function, without significantly changing one of its properties (fewer lines, better error checking, faster run time, etc. etc. etc.) is there really any benefit? And if your functions do meet those criteria you should explain exactly how it does so, so forum members can benefit.


"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By HurleyShanabarger
      Hello,
       
      I am trying to convert code from C# to AutoIt. This is the code:
      byte[] lv_aKey = { 23, 82, 107, 6, 35, 78, 88, 7 }; byte[] lv_aPwd = ToByteArray(password); //--> here I don't know which AutoIt function to use DES des = new DESCryptoServiceProvider(); des.Padding = PaddingMode.None; des.Mode = CipherMode.ECB; ICryptoTransform dec = des.CreateDecryptor(lv_aKey, null); dec.TransformBlock(lv_aPwd, 0, lv_aPwd.Length, response, 0); //<-- here I don't know which AutoIt function to use return System.Text.ASCIIEncoding.ASCII.GetString(response); I am having problems with the crypt functions - can someone point me in the right direction?
    • By nacerbaaziz
      it recomended to use the builten function
      _DateDiff
       
       
       
      hello autoit team
      i made a simple function to help me get the difference between to date
      i liked to share it with you
      the paramatrs of this function
      is firstdate and lastedate
      the two params is as the following
      year/month/day hours:minuts:seconds
      here is the function
       
      #include <date.au3> func _dateBetween($s_firstDate, $s_lastDate = default) if not (StringRegExp($s_firstDate, "((\d{4})\/(\d{2})\/(\d{2})\s(\d{2})\:(\d{2})\:(\d{2}))", 0) = 1) then Return SetError(1, 0, 0) if $s_lastDate = default then $s_lastDate = @year & "/" & @mon & "/" & @mday & " " & @hour & ":" & @min & ":" & @sec if not (StringRegExp($s_lastDate, "((\d{4})\/(\d{2})\/(\d{2})\s(\d{2})\:(\d{2})\:(\d{2}))", 0) = 1) then Return SetError(2, 0, 0) local $a_FirstSplitDate = StringSplit(StringRegExpReplace($s_firstDate, "((.*)\s(.*))", "$2"), "/", 2) local $a_FirstSplitTime = StringSplit(StringRegExpReplace($s_firstDate, "((.*)\s(.*))", "$3"), ":", 2) local $a_lastSplitDate = StringSplit(StringRegExpReplace($s_lastDate, "((.*)\s(.*))", "$2"), "/", 2) local $a_LastSplitTime = StringSplit(StringRegExpReplace($s_lastDate, "((.*)\s(.*))", "$3"), ":", 2) local $i_firstDateValue = _DateToDayValue($a_FirstSplitDate[0], $a_FirstSplitDate[1], $a_FirstSplitDate[2]) local $i_LastDateValue = _DateToDayValue($a_LastSplitDate[0], $a_LastSplitDate[1], $a_LastSplitDate[2]) if $i_firstDateValue > $i_LastDateValue then Return SetError(3, 0, 0) local $i_totalDays = $i_LastDateValue-$i_firstDateValue if not ($i_totalDays = 0) then if $a_FirstSplitTime[0] <= $a_lastSplitTime[0] then $i_totalDays += 1 $a_lastSplitTime[0] -= $a_FirstSplitTime[0] elseIf $a_FirstSplitTime[0] > $a_lastSplitTime[0] then if $i_totalDays > 0 then $i_totalDays -= 1 $a_FirstSplitTime[0] -= $a_lastSplitTime[0] endIf endIf endIf local $i_totalYears = 0 if $i_totalDays >= 365 then While $i_totalDays >= 365 $i_totalYears += 1 $i_totalDays -= 365 Wend endIf local $i_TotalMonths = 0 if $i_totalDays >= 30 then While $i_totalDays >= 30 $i_totalMonths += 1 $i_totalDays -= 30 Wend endIf local $i_totalWeeks = 0 if $i_totalDays >= 7 then While $i_totalDays >= 7 $i_totalWeeks += 1 $i_totalDays -= 7 Wend endIf $i_totalSeconds = ((($a_FirstSplitTime[0]*60)*60)+($a_FirstSplitTime[1]*60)+($a_FirstSplitTime[2]))-((($a_lastSplitTime[0]*60)*60)+($a_lastSplitTime[1]*60)+($a_LastSplitTime[2])) local $minus = "" if $i_totalSeconds < 0 then $minus = "-" $i_totalSeconds = StringReplace($i_totalSeconds, "-", "") endIf local $i_totalHours = 0 if $i_totalSeconds >= 3600 then While $i_totalSeconds >= 3600 $i_totalHours += 1 $i_totalSeconds -= 3600 Wend endIf local $i_totalminuts = 0 if $i_totalSeconds >= 60 then While $i_totalSeconds >= 60 $i_totalminuts += 1 $i_totalSeconds -= 60 Wend endIf local $a_arrayReturn[7] $a_arrayReturn[0] = $i_totalYears $a_arrayReturn[1] = $i_totalMonths $a_arrayReturn[2] = $i_totalWeeks $a_arrayReturn[3] = $i_totalDays $a_arrayReturn[4] = $minus & $i_totalHours $a_arrayReturn[5] = $minus & $i_totalminuts $a_arrayReturn[6] = $minus & $i_totalSeconds return $a_arrayReturn endFunc  
      here is an example
       
       
      $a_calc = _dateBetween("2015/02/12 23:00:05", "2030/02/12 23:25:50") msgBox(64, "result", StringFormat("the difference is : %i years and %i months and %i weeks and %i days and %i hours and %i minuts and %i seconds", $a_calc[0], $a_calc[1], $a_calc[2], $a_calc[3], $a_calc[4], $a_calc[5], $a_calc[6]))  
      am waiting for your comments
      with my greetings
    • By Jahar
      Hi All,
      Please help me on how to fetch date/time of last windows 10 system restore point using autoit? Basically its about querying the last restore point.
    • By TheDcoder
      Hi everyone,
      I am bit stumped as to why I am not able to set the time in the Date control
      #include <DateTimeConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Example() Func Example() GUICreate("My GUI get date", 200, 200, 800, 200) Local $idDate = GUICtrlCreateDate("1953/04/25", 10, 10, 185, 20, $DTS_TIMEFORMAT) ; to select a specific default format Local $sStyle = "HH:mm:ss" GUICtrlSendMsg($idDate, $DTM_SETFORMATW, 0, $sStyle) ; Set time Local $iRet = GUICtrlSetData($idDate, '13:33:37') ConsoleWrite('GUICtrlSetData returned ' & ($iRet = 1 ? 'success' : 'failure') & @CRLF) GUISetState(@SW_SHOW) ; Loop until the user exits. While GUIGetMsg() <> $GUI_EVENT_CLOSE WEnd MsgBox($MB_SYSTEMMODAL, "Time", GUICtrlRead($idDate)) EndFunc ;==>Example The documentation for GUICtrlSetData clearly mentions that it uses the same format as GUICtrlRead:
      But I get failure
      What gives?
      Thanks for the help in advance!
    • By cruisepandey
      Hi, 
      I have a string like this : 
      Global $Msga = "urrent directory is /send.  (Submission of file with log number 29381077284 is confirmed)";
      I want to extract the number 29381077284  from the string. I did StringSplit to split based on "(" and then use space to reach there, But it's not a good choice. 
      Can anyone help me with regular expression to find the number from String using AutoIT. TIA
×
×
  • Create New...