cmd-util/StringX.au3
2025-08-21 16:55:17 +08:00

833 lines
25 KiB
AutoIt

#NoTrayIcon
#Include <String.au3>
#Include <StringConstants.au3>
#Include <File.au3>
; 2016/12/08 Add /H2S & /S2H Function
#CS ----------------------------------------------------------------------------
If $CMDLINE[0] < 1 Then _Usage()
Switch $CMDLINE[1]
Case "/?"
_Usage()
Case "/BTW"
_StrBetween()
Case "/CMP"
_StrCompare()
Case "/FMT"
_StringFormat()
Case "/SIS"
_StringInStr()
Case "/DIV"
_StrDivision()
Case "/PAR"
_StrSplit()
Case "/ISR"
_StrInsert()
Case "/IAN"
_StrIsAlNum()
Case "/ALP"
_StrIsAlpha()
Case "/ASC"
_StrIsASCII()
Case "/DIG"
_StrIsDigit()
Case "/SIL"
_StrIsLower()
Case "/SIU"
_StrIsUpper()
Case "/BLK"
_StrIsSpace()
Case "/HEX"
_StrIsHEX()
Case "/LEN"
_StrLenth()
Case "/LFT"
_StrLeft()
Case "/RIT"
_StrRight()
Case "/STL"
_StrTrimLeft()
Case "/STR"
_StrTrimRight()
Case "/MID"
_StrMid()
Case "/SRP"
_StrReplace()
Case "/REV"
_StrReverse()
Case "/SWS"
_StrStripWS()
Case Else
_Usage()
EndSwitch
#CE ----------------------------------------------------------------------------
Func _StrBetween()
Local $Tips = @CRLF & "CMD:" & @TAB & "/BTW ""String"" ""Start"" ""End"" [Mode=0] [Case=0]" & @CRLF _
& "Usage:" & @TAB & "Find strings between two string delimiters." & @CRLF & @CRLF _
& "Parameters:" & @CRLF _
& "String:" & @TAB & "The string to search." & @CRLF _
& "Start:" & @TAB & "The beginning of the string to find." & @CRLF _
& @TAB & "(If empty, starts at the beginning.)" & @CRLF _
& "End:" & @TAB & "The end of the string to find." & @CRLF _
& @TAB & "(If empty, searches from ""Start"" to end of string.)" & @CRLF _
& "Mode: (Optional)" & @CRLF _
& @TAB & "0: The ""End"" string at the end of a match starts the next possible match." & @CRLF _
& @TAB & "1: A further instance of the ""Start"" starts the next match." & @CRLF _
& "Case: (Optional)" & @CRLF _
& @TAB & "0: Case-Insensitive." & @CRLF _
& @TAB & "1: Case-Sensitive." & @CRLF _
& "Return Code:" & @CRLF _
& @TAB & "Success: The first found strings." & @CRLF _
& @TAB & "Fail: Error." & @CRLF & @CRLF _
& "Use /F:FileName to set ""String"" as the contents of the specified file." & @CRLF
If $CMDLINE[0] < 2 Then
ConsoleWrite($Tips)
Exit 0
Else
If $CMDLINE[2] = "/?" Then
ConsoleWrite($Tips)
Exit 0
Else
Local $sString = $CMDLINE[2]
Local $sStart = ''
Local $sEnd = ''
Local $iMode = 0
Local $iCase = 0
If $CMDLINE[0] >= 3 Then Local $sStart = $CMDLINE[3]
If $CMDLINE[0] >= 4 Then Local $sEnd = $CMDLINE[4]
If $CMDLINE[0] >= 5 Then
If $CMDLINE[5] = 0 Then
Local $iMode = 0
Else
Local $iMode = 1
EndIf
EndIf
EndIf
EndIf
If $CMDLINE[0] >= 6 Then Local $iCase = $CMDLINE[6]
$sString = StringReplace($sString, "@CRLF", @CRLF)
$sString = StringReplace($sString, "@CR", @CR)
$sString = StringReplace($sString, "@LF", @LF)
If StringLeft($sString, 3) = "/F:" Then
Local $sFile = StringTrimLeft( $sString, 3 )
Local $File = FileOpen($sFile)
Local $sString = FileRead($File)
FileClose($File)
EndIf
$RET = _StringBetween( $sString, $sStart, $sEnd, $iMode, $iCase)
If IsArray($RET) Then
ConsoleWrite("--> Total SubStrings: " & UBound($RET) &@CRLF)
For $i = 0 To UBound($RET) - 1
ConsoleWrite("#"&$i&":"&@TAB&$RET[$i] &@CRLF)
Next
Exit 0
Else
ConsoleWrite(">>> Errors Occurred." &@CRLF)
Exit 0
EndIf
EndFunc
Func _StrCompare()
Local $Tips = @CRLF & "CMD:" & @TAB & "/CMP ""String1"" ""String2"" [CaseSense=0/1]" & @CRLF _
& "Usage:" & @TAB & "Compare two strings with options." & @CRLF _
& "Return Code:" & @CRLF _
& " 0: String1 and String2 are equal." & @CRLF _
& " 1: String1 is greater than String2." & @CRLF _
& " -1: String1 is less than String2." & @CRLF
If $CMDLINE[0] < 2 Then
ConsoleWrite("Parameters Format Error." & @CRLF & $Tips)
Exit
ElseIf $CMDLINE[0] = 2 Then
If $CMDLINE[2] = "/?" Then
ConsoleWrite($Tips)
Exit
Else
ConsoleWrite("Parameters Format Error." & @CRLF & $Tips)
Exit
EndIf
ElseIf $CMDLINE[0] = 3 Then
Local $Case = 0
ElseIf $CMDLINE[0] = 4 Then
Local $Case = $CMDLINE[4]
Else
Local $Case = $CMDLINE[4]
EndIf
Local $RET = StringCompare($CMDLINE[2],$CMDLINE[3],$Case)
ConsoleWrite($RET &@CRLF)
Exit 0
EndFunc
Func _StringFormat()
Local $Tips = @CRLF & "CMD:" & @TAB & "/FMT String" & @CRLF _
& "Usage:" & @TAB & "Return a C sprintf() style string." & @CRLF
Local $sParam = StringTrimLeft($CMDLINERAW, StringLen($CMDLINE[1]))
Local $RET = StringFormat($CMDLINE[2], $sParam)
ConsoleWrite($RET&@CRLF)
Exit 0
EndFunc
Func _StringInStr()
Local $Tips = @CRLF & "CMD:" & @TAB & "/SIS String Substring [Case] [Occurrence] [Start] [Count]" & @CRLF _
& "Usage:" & @TAB & "Check if a string contains a given substring." & @CRLF & @CRLF _
& "Parameters:" & @CRLF _
& "String:" & @TAB & @TAB & "The string to evaluate. " & @CRLF _
& "Substring:" & @TAB & "The substring to search for. " & @CRLF _
& "Case:" & @TAB & @TAB & "Indicate if the operation should be case sensitive(0/1)." & @CRLF _
& "Occurrence:" & @TAB & "Occurrence of the substring to find in the string.(Def=1)" & @CRLF _
& "Start:" & @TAB & @TAB & "The starting position of the search.(Def=1)" & @CRLF _
& "Count:" & @TAB & @TAB & "Number of char to search, must be longer than the substring." & @CRLF & @CRLF _
& "Return Code: " & @CRLF _
& "Success: The position of the substring." & @CRLF _
& "Failure: Return 0 if substring not found." & @CRLF
If $CMDLINE[0] < 3 Then
ConsoleWrite("Parameters Format Error." & @CRLF & $Tips)
Exit 0
EndIf
If StringLeft($CMDLINE[2],3) = "/F:" Then
Local $FileName = StringTrimLeft($CMDLINE[2],3)
Local $File = FileOpen($FileName,0)
Local $Str = FileRead($File)
Else
Local $Str = $CMDLINE[2]
$Str = StringReplace($Str, "@CRLF", @CRLF)
$Str = StringReplace($Str, "@CR", @CR)
$Str = StringReplace($Str, "@LF", @LF)
EndIf
If StringLeft($CMDLINE[3],3) = "/F:" Then
Local $FileName = StringTrimLeft($CMDLINE[3],3)
Local $File = FileOpen($FileName,0)
Local $SubStr = FileRead($File)
Else
Local $SubStr = $CMDLINE[3]
$SubStr = StringReplace($SubStr, "@CRLF", @CRLF)
$SubStr = StringReplace($SubStr, "@CR", @CR)
$SubStr = StringReplace($SubStr, "@LF", @LF)
EndIf
Local $iCase = 0
Local $iOccur = 1
Local $iStart = 1
Local $iCount = ""
If $CMDLINE[0] >= 4 Then Local $iCase = $CMDLINE[4]
If $CMDLINE[0] >= 5 Then Local $iOccur = $CMDLINE[5]
If $CMDLINE[0] >= 6 Then Local $iStart = $CMDLINE[6]
If $CMDLINE[0] >= 7 Then
Local $iCount = $CMDLINE[7]
If $iCount < StringLen($CMDLINE[3]) Then
Local $Err = @CRLF & "Parameters Error." & @CRLF _
& "The ""Count"" parameter must be longer than the substring." & @CRLF
ConsoleWrite($Err)
Exit
EndIf
EndIf
If $CMDLINE[0] >= 7 Then
Local $RET = StringInStr($Str, $SubStr, $iCase, $iOccur, $iStart, $iCount)
ConsoleWrite($RET &@CRLF)
Exit 0
Else
Local $RET = StringInStr($Str, $SubStr, $iCase, $iOccur, $iStart)
ConsoleWrite($RET &@CRLF)
Exit 0
EndIf
EndFunc
Func _StrExplode()
Local $Tips = @CRLF & "CMD:" & @TAB & "/DIV String Delimiter [Limit=0]" & @CRLF _
& "Usage:" & @TAB & "Split up a string into substrings depending on the given delimiters." & @CRLF & @CRLF _
& "Parameters:" & @CRLF _
& "String:" & @TAB & @TAB & "String to be split." & @CRLF _
& "Delimiter:" & @TAB & "Delimiter to split on." & @CRLF _
& "Limit:" & @TAB & @TAB & "(Optional) Maximum elements to be returned." & @CRLF _
& @TAB & @TAB & "=0: (Default) Split on every instance of the delimiter." & @CRLF _
& @TAB & @TAB & ">0: Split until limit, last element will contain remaining portion." & @CRLF _
& @TAB & @TAB & "<0: Split on every instance, removing limit count from end of the array." & @CRLF & @CRLF _
& "Return Value:" & @TAB & "Return an array containing the exploded strings." & @CRLF & @CRLF _
& "Use /F:FileName to set ""String"" as the contents of the specified file." & @CRLF
If $CMDLINE[0] < 3 Then
ConsoleWrite($Tips)
Exit 0
ElseIf $CMDLINE[0] = 3 Then
Local $iLimit = 0
Else
Local $iLimit = $CMDLINE[4]
EndIf
Local $sString = $CMDLINE[2]
$sString = StringReplace($sString, "@CRLF", @CRLF)
$sString = StringReplace($sString, "@CR", @CR)
$sString = StringReplace($sString, "@LF", @LF)
If StringLeft($sString, 3) = "/F:" Then
Local $sFile = StringTrimLeft( $sString, 3 )
Local $File = FileOpen($sFile)
Local $sString = FileRead($File)
FileClose($File)
EndIf
Local $RET = _StringExplode($sString, $CMDLINE[3], $iLimit)
If IsArray($RET) Then
ConsoleWrite("--> Matching SubStrings: " & UBound($RET) & @CRLF)
For $i = 0 To UBound($RET) - 1
ConsoleWrite("#"&$i&":"&@TAB&$RET[$i] &@CRLF)
Next
Exit 0
Else
ConsoleWrite(">>> Errors Occurred." & @CRLF)
Exit 0
EndIf
EndFunc
Func _StrSplit()
Local $Tips = @CRLF & "CMD:" & @TAB & "/PAR String Delimiter [Flag=0]" & @CRLF _
& "Usage:" & @TAB & "Split up a string into substrings depending on the given delimiters." & @CRLF & @CRLF _
& "Parameters:" & @CRLF _
& "String:" & @TAB & @TAB & "String to be split." & @CRLF _
& "Delimiter:" & @TAB & "Delimiter to split on." & @CRLF _
& "Flag:" & @TAB & @TAB & "(Optional) Changes how the string split works." & @CRLF _
& @TAB & @TAB & "=0: Each character of the delimiter will mark the split." & @CRLF _
& @TAB & @TAB & "=1: Entire delimiter string is needed to mark the split." & @CRLF & @CRLF _
& "Return Value:" & @TAB & "Return an array containing the exploded strings." & @CRLF & @CRLF _
& "Use /F:FileName to set ""String"" as the contents of the specified file." & @CRLF
If $CMDLINE[0] < 3 Then
ConsoleWrite($Tips)
Exit 0
ElseIf $CMDLINE[0] = 3 Then
Local $iFlag = $STR_CHRSPLIT
Else
Local $iFlag = $CMDLINE[4]
If $iFlag = 0 Then $iFlag = $STR_CHRSPLIT
If $iFlag = 1 Then $iFlag = $STR_ENTIRESPLIT
If $iFlag <> 1 And $iFlag <> 0 Then $iFlag = $STR_NOCOUNT
EndIf
Local $sString = $CMDLINE[2]
$sString = StringReplace($sString, "@CRLF", @CRLF)
$sString = StringReplace($sString, "@CR", @CR)
$sString = StringReplace($sString, "@LF", @LF)
If StringLeft($sString, 3) = "/F:" Then
Local $sFile = StringTrimLeft( $sString, 3 )
Local $File = FileOpen($sFile)
Local $sString = FileRead($File)
FileClose($File)
EndIf
Local $RET = StringSplit($sString, $CMDLINE[3], $iFlag)
If IsArray($RET) Then
ConsoleWrite("--> Matching SubStrings: " & $RET[0] & @CRLF)
For $i = 1 To $RET[0]
ConsoleWrite("#"&$i&":"&@TAB&$RET[$i] & @CRLF)
Next
Exit 0
Else
ConsoleWrite(">>> Errors Occurred." &@CRLF)
Exit 0
EndIf
EndFunc
Func _StrInsert()
Local $Tips = @CRLF & "CMD:" & @TAB & "/ISR String InsertStr Position" & @CRLF _
& "Usage:" & @TAB & "Insert a string within another string." & @CRLF & @CRLF _
& "Parameters:" & @CRLF _
& "String:" & @TAB & @TAB & "Original string." & @CRLF _
& "InsertStr:" & @TAB & "String to be inserted." & @CRLF _
& "Position:" & @TAB & "Position to insert string." & @CRLF _
& @TAB & @TAB & "(Negatives values count from right hand side)." & @CRLF & @CRLF _
& "Return Value:" & @CRLF _
& @TAB & "Success: The modified string." & @CRLF _
& @TAB & "Failure: The original string." & @CRLF
If $CMDLINE[0] < 4 Then
ConsoleWrite($Tips)
Exit 0
EndIf
Local $RET = _StringInsert($CMDLINE[2], $CMDLINE[3], $CMDLINE[4])
ConsoleWrite($RET&@CRLF)
Exit 0
EndFunc
Func _StrIsAlNum()
Local $Tips = @CRLF & "CMD:" & @TAB & "/IAN String" & @CRLF _
& "Usage:" & @TAB & "Check if a string contains only alphanumeric characters." & @CRLF & @CRLF _
& "Error Code:" & @CRLF _
& " 0: String contains only alphanumeric characters." & @CRLF _
& " 1: String contains non-alphanumeric characters." & @CRLF
If $CMDLINE[0] < 2 Then
ConsoleWrite($Tips)
Exit 0
Else
Local $RET = StringIsAlNum($CMDLINE[2])
If $RET = 1 Then
ConsoleWrite("String: " & $CMDLINE[2] & @CRLF & "ErrorCode: 0" & @CRLF)
Exit 0
Else
ConsoleWrite("String: " & $CMDLINE[2] & @CRLF & "ErrorCode: 1" & @CRLF)
Exit 1
EndIf
EndIf
EndFunc
Func _StrIsAlpha()
Local $Tips = @CRLF & "CMD:" & @TAB & "/ALP String" & @CRLF _
& "Usage:" & @TAB & "Check if a string contains only alphabetic characters." & @CRLF & @CRLF _
& "Error Code:" & @CRLF _
& " 0: String contains only alphabetic characters." & @CRLF _
& " 1: String contains non-alphabetic characters." & @CRLF
If $CMDLINE[0] < 2 Then
ConsoleWrite($Tips)
Exit 0
Else
Local $RET = StringIsAlpha($CMDLINE[2])
If $RET = 1 Then
ConsoleWrite("String: " & $CMDLINE[2] & @CRLF & "ErrorCode: 0" & @CRLF)
Exit 0
Else
ConsoleWrite("String: " & $CMDLINE[2] & @CRLF & "ErrorCode: 1" & @CRLF)
Exit 1
EndIf
EndIf
EndFunc
Func _StrIsASCII()
Local $Tips = @CRLF & "CMD:" & @TAB & "/ASC String" & @CRLF _
& "Usage:" & @TAB & "Check if a string contains only ASCII characters(0x00 - 0x7f)." & @CRLF & @CRLF _
& "Error Code:" & @CRLF _
& " 0: String contains only ASCII characters." & @CRLF _
& " 1: String contains extended ASCII characters." & @CRLF
If $CMDLINE[0] < 2 Then
ConsoleWrite($Tips)
Exit 0
Else
Local $RET = StringIsASCII($CMDLINE[2])
If $RET = 1 Then
ConsoleWrite("String: " & $CMDLINE[2] & @CRLF & "ErrorCode: 0" & @CRLF)
Exit 0
Else
ConsoleWrite("String: " & $CMDLINE[2] & @CRLF & "ErrorCode: 1" & @CRLF)
Exit 1
EndIf
EndIf
EndFunc
Func _StrIsDigit()
Local $Tips = @CRLF & "CMD:" & @TAB & "/DIG String" & @CRLF _
& "Usage:" & @TAB & "Check if a string contains only digit (0-9) characters." & @CRLF & @CRLF _
& "Error Code:" & @CRLF _
& " 0: String contains only digit characters." & @CRLF _
& " 1: String contains non-digits characters." & @CRLF
If $CMDLINE[0] < 2 Then
ConsoleWrite($Tips)
Exit 0
Else
Local $RET = StringIsDigit($CMDLINE[2])
If $RET = 1 Then
ConsoleWrite("String: " & $CMDLINE[2] & @CRLF & "ErrorCode: 0" & @CRLF)
Exit 0
Else
ConsoleWrite("String: " & $CMDLINE[2] & @CRLF & "ErrorCode: 1" & @CRLF)
Exit 1
EndIf
EndIf
EndFunc
Func _StrIsLower()
Local $Tips = @CRLF & "CMD:" & @TAB & "/LOW String" & @CRLF _
& "Usage:" & @TAB & "Check if a string contains only lowercase characters." & @CRLF & @CRLF _
& "Error Code:" & @CRLF _
& " 0: String contains only lowercase characters." & @CRLF _
& " 1: String contains non-lowercase characters." & @CRLF
If $CMDLINE[0] < 2 Then
ConsoleWrite($Tips)
Exit 0
Else
Local $RET = StringIsLower($CMDLINE[2])
If $RET = 1 Then
ConsoleWrite("String: " & $CMDLINE[2] & @CRLF & "ErrorCode: 0" & @CRLF)
Exit 0
Else
ConsoleWrite("String: " & $CMDLINE[2] & @CRLF & "ErrorCode: 1" & @CRLF)
Exit 1
EndIf
EndIf
EndFunc
Func _StrIsUpper()
Local $Tips = @CRLF & "CMD:" & @TAB & "/UPR String" & @CRLF _
& "Usage:" & @TAB & "Check if a string contains only lowercase characters." & @CRLF & @CRLF _
& "Error Code:" & @CRLF _
& " 0: String contains only uppercase characters." & @CRLF _
& " 1: String contains non-uppercase characters." & @CRLF
If $CMDLINE[0] < 2 Then
ConsoleWrite($Tips)
Exit 0
Else
Local $RET = StringIsUpper($CMDLINE[2])
If $RET = 1 Then
ConsoleWrite("String: " & $CMDLINE[2] & @CRLF & "ErrorCode: 0" & @CRLF)
Exit 0
Else
ConsoleWrite("String: " & $CMDLINE[2] & @CRLF & "ErrorCode: 1" & @CRLF)
Exit 1
EndIf
EndIf
EndFunc
Func _StrIsSpace()
Local $Tips = @CRLF & "CMD:" & @TAB & "/BLK String" & @CRLF _
& "Usage:" & @TAB & "Check if a string contains only whitespace characters." & @CRLF & @CRLF _
& "Error Code:" & @CRLF _
& " 0: String contains only whitespace characters." & @CRLF _
& " 1: String contains non-whitespace characters." & @CRLF
If $CMDLINE[0] < 2 Then
ConsoleWrite($Tips)
Exit 0
Else
Local $RET = StringIsSpace($CMDLINE[2])
If $RET = 1 Then
ConsoleWrite("String: " & $CMDLINE[2] & @CRLF & "ErrorCode: 0" & @CRLF)
Exit 0
Else
ConsoleWrite("String: " & $CMDLINE[2] & @CRLF & "ErrorCode: 1" & @CRLF)
Exit 1
EndIf
EndIf
EndFunc
Func _StrIsHEX()
Local $Tips = @CRLF & "CMD:" & @TAB & "/HEX String" & @CRLF _
& "Usage:" & @TAB & "Check if a string are hexadecimal digit (0-9, A-F) characters." & @CRLF & @CRLF _
& "Error Code:" & @CRLF _
& " 0: String contains only hexadecimal characters." & @CRLF _
& " 1: String contains non-hexadecimal characters." & @CRLF
If $CMDLINE[0] < 2 Then
ConsoleWrite($Tips)
Exit 0
Else
Local $RET = StringIsXDigit($CMDLINE[2])
If $RET = 1 Then
ConsoleWrite("String: " & $CMDLINE[2] & @CRLF & "ErrorCode: 0" & @CRLF)
Exit 0
Else
ConsoleWrite("String: " & $CMDLINE[2] & @CRLF & "ErrorCode: 1" & @CRLF)
Exit 1
EndIf
EndIf
EndFunc
Func _StrLength()
Local $Tips = @CRLF & "CMD:" & @TAB & "/LEN String" & @CRLF _
& "Usage:" & @TAB & "Return the number of characters in a string." & @CRLF & @CRLF _
& "Return Value: The length of the string." & @CRLF
If $CMDLINE[0] < 2 Then
ConsoleWrite($Tips)
Exit 0
Else
Local $RET = StringLen($CMDLINE[2])
ConsoleWrite("String: " & $CMDLINE[2] & @CRLF & "Length: " & $RET & @CRLF)
Exit 0
EndIf
EndFunc
Func _StrLeft()
Local $Tips = @CRLF & "CMD:" & @TAB & "/LFT String Count" & @CRLF _
& "Usage:" & @TAB & "Return a number of characters from the left side of a string." & @CRLF & @CRLF _
& "Parameters:" & @CRLF _
& "String:" & @TAB & "The string to evaluate." & @CRLF _
& "Count:" & @TAB & "The number of characters to get." & @CRLF
If $CMDLINE[0] < 3 Then
ConsoleWrite($Tips)
Exit 0
Else
If $CMDLINE[2] = "/?" Then
ConsoleWrite($Tips)
Exit 0
Else
Local $RET = StringLeft($CMDLINE[2], $CMDLINE[3])
ConsoleWrite($RET&@CRLF)
Exit 0
EndIf
EndIf
EndFunc
Func _StrRight()
Local $Tips = @CRLF & "CMD:" & @TAB & "/RIT String Count" & @CRLF _
& "Usage:" & @TAB & "Return a number of characters from the right side of a string." & @CRLF & @CRLF _
& "Parameters:" & @CRLF _
& "String:" & @TAB & "The string to evaluate." & @CRLF _
& "Count:" & @TAB & "The number of characters to get." & @CRLF
If $CMDLINE[0] < 3 Then
ConsoleWrite($Tips)
Exit 0
Else
If $CMDLINE[2] = "/?" Then
ConsoleWrite($Tips)
Exit 0
Else
Local $RET = StringRight($CMDLINE[2], $CMDLINE[3])
ConsoleWrite($RET&@CRLF)
Exit 0
EndIf
EndIf
EndFunc
Func _StrTrimLeft()
Local $Tips = @CRLF & "CMD:" & @TAB & "/STL String Count" & @CRLF _
& "Usage:" & @TAB & "Trim a number of characters from the left side of a string." & @CRLF & @CRLF _
& "Parameters:" & @CRLF _
& "String:" & @TAB & "The string to evaluate." & @CRLF _
& "Count:" & @TAB & "The number of characters to trim." & @CRLF
If $CMDLINE[0] < 3 Then
ConsoleWrite($Tips)
Exit 0
Else
If $CMDLINE[2] = "/?" Then
ConsoleWrite($Tips)
Exit 0
Else
Local $RET = StringTrimLeft($CMDLINE[2], $CMDLINE[3])
ConsoleWrite($RET&@CRLF)
Exit 0
EndIf
EndIf
EndFunc
Func _StrTrimRight()
Local $Tips = @CRLF & "CMD:" & @TAB & "/STR String Count" & @CRLF _
& "Usage:" & @TAB & "Trim a number of characters from the right side of a string." & @CRLF & @CRLF _
& "Parameters:" & @CRLF _
& "String:" & @TAB & "The string to evaluate." & @CRLF _
& "Count:" & @TAB & "The number of characters to trim." & @CRLF
If $CMDLINE[0] < 3 Then
ConsoleWrite($Tips)
Exit 0
Else
If $CMDLINE[2] = "/?" Then
ConsoleWrite($Tips)
Exit 0
Else
Local $RET = StringTrimRight($CMDLINE[2], $CMDLINE[3])
ConsoleWrite($RET&@CRLF)
Exit 0
EndIf
EndIf
EndFunc
Func _StrMid()
Local $Tips = @CRLF & "CMD:" & @TAB & "/MID String Start [Count]" & @CRLF _
& "Usage:" & @TAB & "Extract a number of characters from a string." & @CRLF & @CRLF _
& "Parameters:" & @CRLF _
& "String:" & @TAB & "The string to evaluate." & @CRLF _
& "Start:" & @TAB & "The character position to start." & @CRLF _
& "Count:" & @TAB & "(Optional) The number of characters to extract." & @CRLF _
& @TAB & "(By default the entire remainder of the string.)" & @CRLF
If $CMDLINE[0] < 3 Then
ConsoleWrite($Tips)
Exit 0
Else
If $CMDLINE[2] = "/?" Then
ConsoleWrite($Tips)
Exit 0
EndIf
EndIf
Local $iCount = -1
If $CMDLINE[0] >=4 Then $iCount = $CMDLINE[4]
Local $RET = StringMid($CMDLINE[2], $CMDLINE[3], $iCount)
ConsoleWrite($RET&@CRLF)
Exit 0
EndFunc
Func _StrReplace()
Local $Tips = @CRLF & "CMD:" & @TAB & "/SRP String SearchStr ReplaceStr [Count=0] [Case=0]" & @CRLF _
& "Usage:" & @TAB & "Replace substrings in a string." & @CRLF & @CRLF _
& "Parameters:" & @CRLF _
& "String:" & @TAB & @TAB & "The string to evaluate." & @CRLF _
& "SearchStr:" & @TAB & "The substring to search for." & @CRLF _
& "ReplaceStr:" & @TAB & "The replacement string." & @CRLF _
& "Count:" & @TAB & @TAB & "The number of times to replace the searchstring." & @CRLF _
& @TAB & @TAB & "All searchstrings will be replaced.(Default=0)" & @CRLF _
& @TAB & @TAB & "Use a negative number to replace from the right side." & @CRLF _
& "Case:" & @TAB & @TAB & "Flag to indicate if the operations should be case sensitive." & @CRLF _
& @TAB & @TAB & "0: Not case sensitive.(Default)" & @CRLF _
& @TAB & @TAB & "1: Case sensitive." & @CRLF & @CRLF _
& "Returen Value: The new string." & @CRLF
If $CMDLINE[0] < 4 Then
ConsoleWrite($Tips)
Exit 0
EndIf
Local $iCount = 0
Local $iCase = 0
If $CMDLINE[0] >= 5 Then $iCount = $CMDLINE[5]
If $CMDLINE[0] >= 6 Then $iCase = $CMDLINE[6]
Local $RET = StringReplace($CMDLINE[2], $CMDLINE[3], $CMDLINE[4], $iCount, $iCase)
ConsoleWrite("--> Occurrence: " & @Extended & @CRLF & $RET & @CRLF)
Exit 0
EndFunc
Func _StrReverse()
Local $Tips = @CRLF & "CMD:" & @TAB & "/REV String" & @CRLF _
& "Usage:" & @TAB & "Reverse the contents of the specified string." & @CRLF & @CRLF
If $CMDLINE[0] < 2 Then
ConsoleWrite($Tips)
Exit 0
Else
Local $RET = StringReverse($CMDLINE[2])
;ConsoleWrite("String: " & $CMDLINE[2] & @CRLF & "Result: " & $RET & @CRLF)
ConsoleWrite($RET&@CRLF)
Exit 0
EndIf
EndFunc
Func _StrStripWS()
Local $Tips = @CRLF & "CMD:" & @TAB & "/SWS String Flag" & @CRLF _
& "Usage:" & @TAB & "Strip the white space in a string." & @CRLF & @CRLF _
& "Parameters:" & @CRLF _
& "String:" & @TAB & "The string to strip." & @CRLF _
& "Flag:" & @TAB & "Flag to indicate the type of stripping." & @CRLF _
& @TAB & "Add the flags together for multiple operations." & @CRLF _
& @TAB & "1: Strip leading white space." & @CRLF _
& @TAB & "2: Strip trailing white space." & @CRLF _
& @TAB & "4: Strip double (or more) spaces between words." & @CRLF _
& @TAB & "8: Strip all spaces (over-rides all other flags)." & @CRLF
If $CMDLINE[0] < 3 Then
ConsoleWrite($Tips)
Exit 0
Else
Local $sString = $CMDLINE[2]
Local $iFlag = $CMDLINE[3]
EndIf
Local $RET = StringStripWS($sString, $iFlag)
ConsoleWrite($RET&@CRLF)
Exit 0
EndFunc
Func _StringLower()
Local $Tips = @CRLF & "CMD:" & @TAB & "/LWR String" & @CRLF _
& "Usage:" & @TAB & "Convert a string to lowercase." & @CRLF & @CRLF
If $CMDLINE[0] < 2 Then
ConsoleWrite($Tips)
Exit 0
Else
Local $RET = StringLower($CMDLINE[2])
;ConsoleWrite("String: " & $CMDLINE[2] & @CRLF & "Result: " & $RET & @CRLF)
ConsoleWrite($RET&@CRLF)
Exit 0
EndIf
EndFunc
Func _StringUpper()
Local $Tips = @CRLF & "CMD:" & @TAB & "/UPR String" & @CRLF _
& "Usage:" & @TAB & "Convert a string to uppercase." & @CRLF & @CRLF
If $CMDLINE[0] < 2 Then
ConsoleWrite($Tips)
Exit 0
Else
Local $RET = StringUpper($CMDLINE[2])
;ConsoleWrite("String: " & $CMDLINE[2] & @CRLF & "Result: " & $RET & @CRLF)
ConsoleWrite($RET&@CRLF)
Exit 0
EndIf
EndFunc
Func _Str2Hex()
Local $Tips = @CRLF & "CMD:" & @TAB & "/S2H String" & @CRLF _
& "Usage:" & @TAB & "Convert a string to a hex string." & @CRLF & @CRLF
If $CMDLINE[0] < 2 Then
ConsoleWrite($Tips)
Exit 0
Else
Local $RET = _StringToHex($CMDLINE[2])
;ConsoleWrite("String: " & $CMDLINE[2] & @CRLF & "Result: " & $RET & @CRLF)
ConsoleWrite($RET&@CRLF)
Exit 0
EndIf
EndFunc
Func _Hex2Str()
Local $Tips = @CRLF & "CMD:" & @TAB & "/H2S String" & @CRLF _
& "Usage:" & @TAB & "Convert a hex string to a string." & @CRLF & @CRLF
If $CMDLINE[0] < 2 Then
ConsoleWrite($Tips)
Exit 0
Else
Local $RET = _HexToString($CMDLINE[2])
;ConsoleWrite("String: " & $CMDLINE[2] & @CRLF & "Result: " & $RET & @CRLF)
ConsoleWrite($RET&@CRLF)
Exit 0
EndIf
EndFunc
;#CS ----------------------------------------
; Switch $iFlag
; Case '/L'
; $iFlag = $STR_STRIPLEADING (1)
; Case '/R'
; $iFlag = $STR_STRIPLEADING (2)
; Case '/S'
; $iFlag = $STR_STRIPLEADING (4)
; Case '/A'
; $iFlag = $STR_STRIPLEADING (8)
; Case Else
; $iFlag = $STR_STRIPLEADING (8)
; EndSwitch
;#CE ----------------------------------------
#CS
Func _Usage()
Global $HelpInfo = @CRLF & "-- String Manage Utility." & @CRLF _
& "Ver 1.0 Build Jun.21 2016." & @CRLF & @CRLF _
& "Command Line: [/Command] <Parameter1> ... " & @CRLF & @CRLF _
& "Commands:" & @CRLF _
& "/CMP" & @TAB & "Compares two strings with options." & @CRLF _
& "/SIS" & @TAB & "Checks if a string contains a given substring." & @CRLF _
ConsoleWrite($HelpInfo)
Exit 0
EndFunc
#CE