Simpel Posted March 2, 2017 Share Posted March 2, 2017 (edited) Hi, I want to set attributes to a file or more. I have an inputbox where I ask for the right attributes. Now I want to delete all not possible letters, digits and whitespaces and return a unique string. So +-RASHNOT should only once appear. Script so far: Test() Func Test() Local $sInput = "+-RASHNOT+-Whhere have all the flowers gone, long time passing? ÄÖÜ 01234567899" $sInput = StringUpper($sInput) Local $sOutput = StringRegExpReplace($sInput, "[^RASHNOT\^+\^-]", "") ; Explizit nur "RASHNOT" und "+" und "-" Display($sInput, $sOutput) EndFunc Func Display($sInput, $sOutput) Local $sMsg = StringFormat("Input:\t%s\n\nOutput:\t%s", $sInput, $sOutput) MsgBox(0, "Results", $sMsg) EndFunc How to kill all r, a, s, h, n, o, t existing more then one time? I don't want to build an array and then _arrayunique. Is there some better way? Regards, Conrad Edited April 25, 2019 by Simpel [Solved] SciTE4AutoIt = 3.7.3.0 AutoIt = 3.3.14.2 AutoItX64 = 0 OS = Win_10 Build = 19044 OSArch = X64 Language = 0407/german H:\...\AutoIt3\SciTE H:\...\AutoIt3 H:\...\AutoIt3\Include (H:\ = Network Drive) Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. Link to comment Share on other sites More sharing options...
Simpel Posted March 2, 2017 Author Share Posted March 2, 2017 (edited) Solution with array and _arrayunique looks now like this: #include <Array.au3> Test("+-RASHNOT+-Whhere have all the flowers gone, long time passing? ÄÖÜ 01234567899") Func Test($sInput) $sInput = StringUpper($sInput) Local $sOutput = StringRegExpReplace($sInput, "[^RASHNOT\^+\^-]", "") ; Explizit nur "RASHNOT" und "+" und "-" Local $aOutput = StringSplit($sOutput, "", 2) $aOutput = _ArrayUnique($aOutput, 0, 0, 0, 0) _ArraySort($aOutput) $sOutput = _ArrayToString($aOutput, "") Display($sInput, $sOutput) EndFunc Func Display($sInput, $sOutput) Local $sMsg = StringFormat("Input:\t%s\n\nOutput:\t%s", $sInput, $sOutput) MsgBox(0, "Results", $sMsg) EndFunc Regards, Conrad Edited March 2, 2017 by Simpel SciTE4AutoIt = 3.7.3.0 AutoIt = 3.3.14.2 AutoItX64 = 0 OS = Win_10 Build = 19044 OSArch = X64 Language = 0407/german H:\...\AutoIt3\SciTE H:\...\AutoIt3 H:\...\AutoIt3\Include (H:\ = Network Drive) Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. Link to comment Share on other sites More sharing options...
Malkey Posted March 2, 2017 Share Posted March 2, 2017 Here is a solution without using arrays. Test2("+-RASHNOT+-Whhere have all the flowers gone, log time passing? ÄÖÜ 01234567899") Func Test2($sInput) Local $Char, $sOutput = "" Local $sInputMod = StringUpper($sInput) $sInputMod = StringRegExpReplace($sInputMod, "([^RASHNOT\+\-])", "") For $i = 1 To StringLen($sInputMod) $Char = StringMid($sInputMod, $i, 1) If StringInStr($sOutput, $Char) = 0 Then $sOutput &= $Char EndIf Next MsgBox(0, "Results", StringFormat("Input:\t%s\n\nOutput:\t%s", $sInput, $sOutput)) EndFunc ;==>Test2 Link to comment Share on other sites More sharing options...
jguinch Posted March 3, 2017 Share Posted March 3, 2017 Another way : $string = InputBox("Attributes to add or remove", 'Please, entrer the attribute(s) to set/clear. e.g. "+A", "+RA-SH", "+A -S -H +R"', "", "", 500, 150) $sAttribAdd = StringRegExpReplace( StringRegExpReplace($string, ".*?(?|\+([RASHNOT]+)|($))", "$1"), "(\w)(?=(?1)*\1)", "") $sAttribDel = StringRegExpReplace( StringRegExpReplace($string, ".*?(?|-([RASHNOT]+)|($))", "$1"), "(\w)(?=(?1)*\1)", "") $sErrors = StringRegExpReplace($sAttribAdd & $sAttribDel, ".*?(?|(\w)(?=(?1)*\1)|($))", "$1") If StringLen($sErrors) Then Exit MsgBox(16, "Error", "You set the following attributes to be added AND removed : " & $sErrors & @CRLF & @CRLF & "Unable to continue.") If Not StringLen($sAttribAdd & $sAttribDel) Then Exit MsgBox(16, "Error", "No valid attribute") MsgBox(0, "Attributes", "Attributes to add: " & $sAttribAdd & @CRLF & _ "Attributes to remove : " & $sAttribDel) The easiest way would be to create a GUI with checkboxes, to prevent input errors. Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF 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