remin Posted October 17, 2013 Share Posted October 17, 2013 (edited) I can't find out how to convert a part of a string to uppercase. p.e. $Clipboard = StringLower(ClipGet()) ;------------- ----------------------my AHK CODE ---------------------------------; Title Case only if word is: 1) at Start of line OR 2) preceding with a space; Clipboard := RegExReplace(Clipboard, "(^|s)(w)", "$1$U2") ; Same as above but only for words > 1 character; Clipboard := RegExReplace(Clipboard, "(^|s)(w)(w+)", "$1$U2$3") : Sentence Case; Clipboard := RegExReplace(Clipboard, "(((^|([.!?]+s+))[a-z])| i | i')", "$u1");------------- ----------------------end AHK CODE --------------------------------- $U2 means in autohotkey that you convert the 2nd caption to Uppercase Can anyone tell me how to do above Replacements in autoit?It cannot be done dynamically as in autohotkey (using $U2 etc), isn't it? Every help is appreciated Edited October 17, 2013 by Melba23 Added SRE to title Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 17, 2013 Moderators Share Posted October 17, 2013 (edited) remin,There is (as far as I know) no equivalent to the $U# syntax in AutoIt, But I am sure the SRE gurus (not me) can come up with something - stick around and see what happens. M23Edit: I have added SRE to the thread title to attract them. Edited October 17, 2013 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Malkey Posted October 17, 2013 Share Posted October 17, 2013 Maybe something like this. Local $sStr = ClipGet() Local $sStr = "a title case only if a word is at start of line. or is preceding with a space." ; Title Case only if word is: 1) at Start of line OR 2) preceding with a space ConsoleWrite(Execute('"' & StringRegExpReplace($sStr, "\b([a-z])", '" & StringUpper("\1") & "') & '"') & @LF) ;Returns: A Title Case Only If A Word Is At Start Of Line. Or Is Preceding With A Space. ; Same as above but only for words > 1 character ConsoleWrite(Execute('"' & StringRegExpReplace($sStr, "\b([a-z])([a-z]+)", '" & StringUpper("\1") & "\2" & "') & '"') & @LF) ;Returns: a Title Case Only If a Word Is At Start Of Line. Or Is Preceding With a Space. ; Sentence Case ConsoleWrite(Execute('"' & StringRegExpReplace($sStr, "(\A|\.\s+)([a-z])", '" & "\1" & StringUpper("\2") & "') & '"') & @LF) ;Returns: A title case only if a word is at start of line. Or is preceding with a space. remin 1 Link to comment Share on other sites More sharing options...
mikell Posted October 17, 2013 Share Posted October 17, 2013 A little suggestion in case of hyphens Local $sStr = "autoit is a freeware basic-like scripting language. most people should be able to pick it up easily " $txt = "Title Case only if word is: 1) at Start of line OR 2) preceding with a space" ;$res = Execute('"' & StringRegExpReplace($sStr, '\b([a-z])', '" & StringUpper("$1") & "') & '"') $res = Execute('"' & StringRegExpReplace($sStr, '\b((?<!\-)[a-z])', '" & StringUpper("$1") & "') & '"') Msgbox(0,"", $txt &@crlf&@crlf& $res) Link to comment Share on other sites More sharing options...
remin Posted October 17, 2013 Author Share Posted October 17, 2013 Hi Malkey, Thank you for writing. However, I can't make it work. The output is the same as the input. With all three regex you gave (and it takes a lot of time to return the string I noted, is that correct?). I just copied above answer and tried it with the clipboard content and the string you gave. ps: tnx Melba for adding SRE to my message Link to comment Share on other sites More sharing options...
BrewManNH Posted October 17, 2013 Share Posted October 17, 2013 There's a _StringTitleCase function in the newest beta version, doesn't work with Unicode very well, but it will capitalize the first character of every word. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
remin Posted October 17, 2013 Author Share Posted October 17, 2013 (edited) A little suggestion in case of hyphens $res = Execute('"' & StringRegExpReplace($sStr, '\b((?<!\-)[a-z])', '" & StringUpper("$1") & "') & '"') Hi Mikell, Thank you. It works fine. I noted that it doesn't work with all ascii characters. I tried to change it to: $res = Execute('"' & StringRegExpReplace($sStr, '\b((?<!\-)[a-zà-ýœß])', '" & StringUpper("$1") & "') & '"') I thought it was the solution but it simply stepped over characters as èéàáùìò.. école ==> éCole può ==> PuÒ Edited October 17, 2013 by remin Link to comment Share on other sites More sharing options...
AZJIO Posted October 17, 2013 Share Posted October 17, 2013 Local $sText = "a title case only if a word is at start of line. or is preceding with a space." $iOffset = 1 Do $aRes = StringRegExp($sText, '\b[a-z]', 1, $iOffset) If @error Then ExitLoop $iOffset = @extended $sText = StringReplace($sText, $iOffset - 1, StringUpper($aRes[0])) Until 0 MsgBox(0, 'Yes?', $sText) My other projects or all Link to comment Share on other sites More sharing options...
remin Posted October 17, 2013 Author Share Posted October 17, 2013 (edited) Found the solution with the help of Mikell's answer: ;title case $result = Execute('"' & StringRegExpReplace($ClipB, "(^|\s|\n^)([a-zà-ýœß])", '$1" & StringUpper("$2") & "') & '"') ;title case > 1 character $result = Execute('"' & StringRegExpReplace($ClipB, "(^|\s|\n^)([a-zà-ýœß])([a-zà-ýœß]+)", '$1" & StringUpper("$2") & "$3') & '"') ;sentence case $result = Execute('"' & StringRegExpReplace($ClipB, "(((^|([.!?]+\s+))[a-zà-ýœß])| i | i')", '" & StringUpper("$1") & "') & '"') Thank you all for your answers and your help Edited October 17, 2013 by remin Link to comment Share on other sites More sharing options...
AZJIO Posted October 17, 2013 Share Posted October 17, 2013 At me #Obfuscator doesn't process such code. My other projects or all Link to comment Share on other sites More sharing options...
BrewManNH Posted October 17, 2013 Share Posted October 17, 2013 Why in the world would you EVER use Execute for something like that? If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
AZJIO Posted October 17, 2013 Share Posted October 17, 2013 I use, but I avoid Obfuscator.html My other projects or all Link to comment Share on other sites More sharing options...
BrewManNH Posted October 17, 2013 Share Posted October 17, 2013 My only point was about wrapping the code inside an Execute statement when it clearly isn't needed. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
AZJIO Posted October 17, 2013 Share Posted October 17, 2013 @remin Take into account any letters Local $sText = "a title case only if a word is at start of line. or is preceding with a space." $iOffset = 1 Do $aRes = StringRegExp($sText, '(?<![\x{41}-\x{ffff}])[\x{41}-\x{ffff}]', 1, $iOffset) If @error Then ExitLoop $iOffset = @extended $sText = StringReplace($sText, $iOffset - 1, StringUpper($aRes[0])) Until 0 MsgBox(0, 'Yes?', $sText) remin 1 My other projects or all Link to comment Share on other sites More sharing options...
BrewManNH Posted October 17, 2013 Share Posted October 17, 2013 That's pretty close to the _StringTitleCase function. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
remin Posted October 23, 2013 Author Share Posted October 23, 2013 Found the solution with the help of Mikell's answer: ;title case $result = Execute('"' & StringRegExpReplace($ClipB, "(^|\s|\n^)([a-zà-ýœß])", '$1" & StringUpper("$2") & "') & '"') ;title case > 1 character $result = Execute('"' & StringRegExpReplace($ClipB, "(^|\s|\n^)([a-zà-ýœß])([a-zà-ýœß]+)", '$1" & StringUpper("$2") & "$3') & '"') ;sentence case $result = Execute('"' & StringRegExpReplace($ClipB, "(((^|([.!?]+\s+))[a-zà-ýœß])| i | i')", '" & StringUpper("$1") & "') & '"') Thank you all for your answers and your help I thought that it was the solution but it doesn't work when there are quotes in the text. p.e. This is a "test" It returns an empty string. Anyone knows why it doesn't accept quotes? Link to comment Share on other sites More sharing options...
BrewManNH Posted October 23, 2013 Share Posted October 23, 2013 Have you looked at the _StringTitleCase function to see how it is done there. Instead of trying to do it all in one shot, it might take more work. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
mikell Posted October 23, 2013 Share Posted October 23, 2013 Quotes are a big trouble in regexes, often I manage this the ass-way by the use of 'Replaces' Local $sStr = 'autoit is a freeware "basic-like" scripting language. most people should be able to pick it up easily ' $sStr = StringReplace($sStr, '"', '§') $res = Execute('"' & StringRegExpReplace($sStr, '\b((?<!\-)[a-z])', '" & StringUpper("$1") & "') & '"') $res = StringReplace($res, '§', '"') Msgbox(0,"", $res) BrewManNH of course you're right but isn't it nice to be able to get solutions in case of slightly different circumstances ? Link to comment Share on other sites More sharing options...
BrewManNH Posted October 23, 2013 Share Posted October 23, 2013 Except that RegEx has the same problem that the _StringProper function does, it doesn't treat a single quote (apostrophe) correctly. Change your string to this and you'll see what I mean. Local $sStr = "autoit's a freeware ""basic-like"" scripting language. most people (should) be able to pick its up easily" If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
mikell Posted October 23, 2013 Share Posted October 23, 2013 Hmm yes I understand what you mean Local $sStr = "autoit's a freeware ""basic-like"" scripting language. most people (should) be able to pick it up easily" $sStr = StringReplace($sStr, "'", '¤a') $sStr = StringReplace($sStr, '"', '§') $res = Execute('"' & StringRegExpReplace($sStr, '\b((?<!\-|\()[a-z])', '" & StringUpper("$1") & "') & '"') $res = StringReplace($res, '§', '"') $res = StringReplace($res, '¤a', "'") It remains manageable (I think so...) but becomes really tricky 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