Simpel

unique letters: +-RASHNOT

4 posts in this topic

#1 ·  Posted (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 by Simpel
correcting code

SciTE = 3.6.2.0/full   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win7Pro SP1   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE   H:\...\AutoIt3   H:\...\AutoIt3\Include   H: = Network Drive

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by Simpel

SciTE = 3.6.2.0/full   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win7Pro SP1   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE   H:\...\AutoIt3   H:\...\AutoIt3\Include   H: = Network Drive

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

Share this post


Link to post
Share on other sites

#3 ·  Posted

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

 

Share this post


Link to post
Share on other sites

#4 ·  Posted

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.

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now