Gianni Posted July 26, 2019 Share Posted July 26, 2019 hello to all how can I clean a string from unwanted chars and keep only chars belonging in the range from asc(32) to asc(127) inclusive and replace all other chars that falls outside that range with another char (a space chr(32) for example) in one shot, using a regular expression? (or whatever else but looping...) example the string: "Hello ☺ «everybody» Love ♥ and peace" should result as "Hello everybody Love and peace" thanks on advance for helping Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Danp2 Posted July 26, 2019 Share Posted July 26, 2019 Try this -- #include <MsgBoxConstants.au3> Test1() ; This example demonstrates a basic replacement. It replaces the vowels aeiou ; with the @ character. Func Test1() Local $sInput = "Hello ☺ «everybody» Love ♥ and peace" Local $sOutput = StringRegExpReplace($sInput, "[^\x00-\x7F]+", " ") Display($sInput, $sOutput) EndFunc ;==>Test1 Func Display($sInput, $sOutput) ; Format the output. Local $sMsg = StringFormat("Input:\t%s\n\nOutput:\t%s", $sInput, $sOutput) MsgBox($MB_SYSTEMMODAL, "Results", $sMsg) EndFunc ;==>Display Gianni and iamtheky 2 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Gianni Posted July 26, 2019 Author Share Posted July 26, 2019 👌It seems to work well Thanks a lot Dan Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Gianni Posted July 26, 2019 Author Share Posted July 26, 2019 (edited) @Danp2, hemmm, sorry, I talked too quickly, that pattern has issues, it doesn't remoove chars below chr(32) and above chr(127)... try this to see the issue: #include <MsgBoxConstants.au3> Test1() ; This example demonstrates a basic replacement. It replaces the vowels aeiou ; with the @ character. Func Test1() Local $sInput = "Hello ☺ " & @CR & "«everybody» Love ♥ " & ChrW(512) & " and peace" Local $sOutput = StringRegExpReplace($sInput, "[^\x00-\x7F]+", " ") Display($sInput, $sOutput) EndFunc ;==>Test1 Func Display($sInput, $sOutput) ; Format the output. Local $sMsg = StringFormat("Input:\t%s\n\nOutput:\t%s", $sInput, $sOutput) MsgBox($MB_SYSTEMMODAL, "Results", $sMsg) EndFunc ;==>Display Edited July 26, 2019 by Chimp it's ok for chars above 127 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Danp2 Posted July 26, 2019 Share Posted July 26, 2019 So... just modify it accordingly. Try this instead -- Local $sOutput = StringRegExpReplace($sInput, "[^\x20-\x7F]+", " ") Gianni 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Gianni Posted July 26, 2019 Author Share Posted July 26, 2019 ah yes, sorry, it was so easy to correct it ... I was almost near to correct it myself too. Thanks again (damn regexp ) Danp2 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... 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