CarlD 18 Posted September 23, 2021 Share Posted September 23, 2021 (edited) Easy to do, but it seems to me that this should be a built-in function -- unless I'm missing something, somewhere.... Updated: UDF _PathSplit returns extension with "." prepended. Why? Extension is a string, "." just happens to be to be the separator, and it forces StringTrimLeft($extension, 1) for no good reason (IMO). #include <File.au3> Global $sDr, $sPa, $sFn, $sEx $sFileFullPath = "d:\path\blah blah blah.foo foo.bar bar.extension" Exit MsgBox( 0, "", _PathSplit($sFileFullPath , $sDr, $sPa, $sFn, $sEx)[4] ) Original function (less expensive??): Func _FileGetExt($sFn) ; Parse EXTension from [d:\path\]filename.EXTension Local $sExt = "", $aA If StringInStr($sFn, ".") Then If Not StringInStr(FileGetAttrib($sFn), "D") Then $aA = StringSplit($sFn, ".") $sExt = $aA[$aA[0]] EndIf EndIf Return $sExt EndFunc ;==>_FileGetExt Edited September 24, 2021 by CarlD Update (thanks to TheDCoder :-)) Link to post Share on other sites
TheDcoder 1,701 Posted September 23, 2021 Share Posted September 23, 2021 @CarlD _PathSplit CarlD 1 EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to post Share on other sites
CarlD 18 Posted September 23, 2021 Share Posted September 23, 2021 12 hours ago, TheDcoder said: @CarlD _PathSplit Ah, thanks! Knew it had to be there, somewhere.... 😁 Link to post Share on other sites
CarlD 18 Posted October 31, 2021 Share Posted October 31, 2021 (edited) Func _ConsoleEraseLine() is for compiled CUI scripts. It allows successive one-line console outputs to be printed to a single line on the screen (by overwriting the previous line). Output lines must NOT end in @LF. Compile the code, then command EraseLineDemo.exe. expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile=EraseLineDemo.exe #AutoIt3Wrapper_UseUpx=y #AutoIt3Wrapper_Change2CUI=y #AutoIt3Wrapper_Run_Au3Stripper=y #AutoIt3Wrapper_AU3Check_Parameters=-w 3 -w 4 -w 5 -w 6 -d #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ; ; CLD rev.10/31/2021 Global $vLine1 = "The quick brown fox jumped over the lazy dog." Global $vLine2 = 9999999 Global $vLine3 = 0000001 Global $vLine4 = "0000001" Global $vLine5 = 3.1416 Global $vLine6 = -9999999 Global $vLine7 = -0000001 Global $vLine8 = "-0000001" Global $vLine9 = -03.1416 Global $vLine10 = "-03.1416" Global $vLine11 = True ConsoleWrite($vLine1) Sleep(2000) _ConsoleEraseLine($vLine1) ConsoleWrite($vLine2) Sleep(2000) _ConsoleEraseLine($vLine2) ConsoleWrite($vLine3) Sleep(2000) _ConsoleEraseLine($vLine3) ConsoleWrite($vLine4) Sleep(2000) _ConsoleEraseLine($vLine4) ConsoleWrite($vLine5) Sleep(2000) _ConsoleEraseLine($vLine5) ConsoleWrite($vLine6) Sleep(2000) _ConsoleEraseLine($vLine6) ConsoleWrite($vLine7) Sleep(2000) _ConsoleEraseLine($vLine7) ConsoleWrite($vLine8) Sleep(2000) _ConsoleEraseLine($vLine8) ConsoleWrite($vLine9) Sleep(2000) _ConsoleEraseLine($vLine9) ConsoleWrite($vLine10) Sleep(2000) _ConsoleEraseLine($vLine10) ConsoleWrite($vLine11) Sleep(2000) _ConsoleEraseLine($vLine11) Exit ConsoleWrite("Done!" & @LF) Func _ConsoleEraseLine($vIn) ; Erase one line (only) from console output (DOS only, not SciTE) ; $vIn = Line_to_Erase ; Does NOT work if line ends with @LF !! If StringRight($vIn, 1) = @LF Then Return Local $sOut = "" For $i = 1 To StringLen($vIn) $sOut &= Chr(8) & " " & Chr(8) Next ConsoleWrite($sOut) EndFunc ;==>_ConsoleEraseLine Edited October 31, 2021 by CarlD Update Link to post Share on other sites
JockoDundee 633 Posted October 31, 2021 Share Posted October 31, 2021 @CarlD, yes but what happens if the string to write and erase is also a valid integer, say 999999999 or 000001 ? CarlD 1 Code hard, but don’t hard code... Link to post Share on other sites
CarlD 18 Posted October 31, 2021 Share Posted October 31, 2021 (edited) 18 hours ago, JockoDundee said: @CarlD, yes but what happens if the string to write and erase is also a valid integer, say 999999999 or 000001 ? @JockoDundee, Yes, I don't think it makes a difference. Once I removed the erroneous IsInt() test, if If you feed an integer like 000001 to ConsoleWrite, it evaluates it (to "1") before writing it to the screen. If you want the output to actually be "000001" it has to be quoted as a string. _ConsoleEraseLine now behaves the same way, so it will (or should) erase whatever ConsoleWrite outputs. Try the updated code in the original snippet -- as modified to respond to your comment -- and see if it works for you. Edited November 1, 2021 by CarlD Eating crow Link to post Share on other sites
JockoDundee 633 Posted October 31, 2021 Share Posted October 31, 2021 28 minutes ago, CarlD said: Try the updated code in the original snippet and see if it works for you. I think it would work now. However, my objection was due to the IsInt() statement in your original code: a line which no longer exists in the refactored code. What was that line supposed to do? TheDcoder and CarlD 1 1 Code hard, but don’t hard code... Link to post Share on other sites
CarlD 18 Posted November 1, 2021 Share Posted November 1, 2021 4 hours ago, JockoDundee said: I think it would work now. However, my objection was due to the IsInt() statement in your original code: a line which no longer exists in the refactored code. What was that line supposed to do? It was supposed to allow inputting either the string itself or an integer representing the length of the string to overwrite -- but as you pointed out, what if the "string" was itself an integer? So I was wrong to say in my last message that "it doesn't make a difference". I'd conveniently forgotten that I modified my code to respond to your comment, and then pretended that there was nothing to your comment in the first place. 😏 Thank you for setting me straight. 😁 TheDcoder 1 Link to post Share on other sites
JockoDundee 633 Posted November 1, 2021 Share Posted November 1, 2021 21 minutes ago, CarlD said: I'd conveniently forgotten that I modified my code to respond to your comment No worries, I just assumed that _ConsoleEraseLine() accidentally ate one of its own lines CarlD and TheDcoder 2 Code hard, but don’t hard code... Link to post Share on other sites
abberration 66 Posted April 12 Share Posted April 12 _StringCapitalize() - version 1.0 I like _StringProper, but it has some unwanted effects, like capitalizing the letter s after an apostrophe (ex: cat's = Cat'S) or letters after other symbols. Also, _StringProper changes all letters after the first to lowercase. With this code, it only capitalizes the first letter and leaves the rest alone. If you use the exceptions option ($text4 example), it makes email addresses all lowercase and deals with names that begin with mc (like McDonald). Lastly, you have the ability to override the default symbols that the script will capitalize afterwards (space, period, comma, brace, bracket, etc.). When you run the example, you will see the difference between _StringProper and _StringCapitalize (standard and with exceptions). It's not perfect (yet), but it's closer to what I want than _StringProper. Usage: _StringCapitalize ( string, [, exceptions= 0 [, symbols="[.| |,|/(|/[|-]" ] ] ) Parameters: string string passed to function exceptions [optional] Default = 0 0 = do not use exceptions 1 = use exceptions symbols [optional] define symbols for function to use #include <String.au3> #include <Array.au3> $text1 = "mcdonald's AshtonK Ke$ha #trending @realcelebrity (etc) TEST@MSN.NET" $text2 = _StringProper($text1) $text3 = _StringCapitalize($text1) $text4 = _StringCapitalize($text1, 1) ; 1 = use email and "mc" exceptions $text5 = _StringCapitalize($text1, 1, "[.| |,|/[|-|#|@|*]") ; user defined symbols - script will capitalize next letter after these symbols. MsgBox(0, "", "Original Text:" & @CRLF & $text1 & @CRLF & @CRLF & "_StringProper:" & @CRLF & $text2 & @CRLF & @CRLF & "_StringCapitalize:" & @CRLF & $text3 & @CRLF & @CRLF & "_StringCapitalize with exceptions:" & @CRLF & $text4 & @CRLF & @CRLF & "_StringCapitalize with exceptions and user specified symbols:" & @CRLF & $text5) Func _StringCapitalize($__sText, $__iExceptions = 0, $__sSymbols = "[.| |,|/(|/[|-]") ; version 1.0 $__aText = StringSplit($__sText, "") For $i = 1 To $__aText[0] If $i = 1 OR StringRegExp($__aText[$i-1], $__sSymbols) = 1 Then $__aText[$i] = StringUpper($__aText[$i]) EndIf Next $__textOut = _ArrayToString($__aText, "", 1) If $__iExceptions = 1 Then ; Lowercase all email addresses $__aExpression = StringRegExp($__textOut, "[\w]+@[\w]+\.+[\w]+", 3) For $i = 1 To UBound($__aExpression) $__textOut = StringReplace($__textOut, $__aExpression[$i - 1], StringLower($__aExpression[$i - 1])) Next $__aExpression = "" ; reset variable ; Format words beginning with mc. Ex: mcdonald = McDonald $__aExpression = StringRegExp($__textOut, "([Mm][Cc][A-Za-z])", 3) For $i = 1 To UBound($__aExpression) $__textOut = StringReplace($__textOut, $__aExpression[$i - 1], "Mc" & StringUpper(StringRight($__aExpression[$i - 1], 1))) Next EndIf Return $__textOut EndFunc robertocm 1 Easy MP3 | Software Installer | Password Manager Link to post Share on other sites
rcmaehl 82 Posted yesterday at 12:08 AM Share Posted yesterday at 12:08 AM (edited) _ArraySafeDelim() - Returns a usable delimiter that is not in the array. Could probably be expanded to use Unicode but I CBA to filter symbols from letters for the entire unicode range. You could technically use letters as a delim but eh, maybe as a flag. Func _ArraySafeDelim($aArray) $sChars = _ArrayToString($aArray) Select Case Not StringInStr($sChars, "|") Return "|" Case Else For $iLoop = 33 To 191 Step 1 Switch $iLoop Case 48 to 57 ; Skip Numbers ContinueLoop Case 65 to 90 ; Skip Upper Case ContinueLoop Case 97 to 122 ; Skip Lower Case ContinueLoop Case Else If Not StringInStr($sChars, Chr($iLoop)) Then Return Chr($iLoop) EndSwitch Next EndSelect ; If No Char Found, Error Return SetError(1, 0, False) EndFunc Edited yesterday at 12:11 AM by rcmaehl My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.My Projects WhyNotWin11Cisco Finesse, Github, IRC UDF, WindowEx UDF Link to post Share on other sites
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