Jump to content

How to make this $Removal case-sensitive?


Recommended Posts

I have a script which copies over text, and I have a filter to remove certain characters before copying.

Local $Removal[5]
                $Removal[0] = "-"
                $Removal[1] = "_"
                $Removal[2] = "."
                $Removal[3] = ","
                $Removal[4] = "l"

As you can see, the first four are just characters. But the last one is a small L

The problem is, it's filtering both the small (l) and the big (L)

But I only want it to filter out the small (l)

Anything I can do to make it case sensitive? Maybe wrap it in some more quotes or something?

Thanks

Link to comment
Share on other sites

7 minutes ago, Jos said:

Make what exactly case sensitive as your posted snippet doesn't demonstrate your issue? ;) 

Hello Jos,

Well, make the "l" case-sensitive.

I explained the issue. So say we have these in a text file:

ab123l

ab123L

 

AutoIt is going to copy them to a different text file.

With the filter above, I will get this in a file:

ab123

ab123

 

But what I want is these in a file:

ab123

ab123L

 

The issue is that the l here isn't case-sensitive:

Local $Removal[5]
                $Removal[0] = "-"
                $Removal[1] = "_"
                $Removal[2] = "."
                $Removal[3] = ","
                $Removal[4] = "l"

 

As for my script, well, this is top-secret CIA operation. Can't be sharing, um, confidential code with the world. Otherwise the terrorists win!!! :D

But here:

Local $SomeFileLocation = @ScriptDir & "\result.txt"

                Local $FuckedUpString = FileRead($SomeFileLocation)
                Local $FuckedUpString1 = StringTrimRight($FuckedUpString, 0)

                Sleep(500)

                Local $FuckedUp2 = $FuckedUpString1
                Local $Cleaner

                Local $Removal[5]
                $Removal[0] = "-"
                $Removal[1] = "_"
                $Removal[2] = "."
                $Removal[3] = ","
                $Removal[4] = "l"

                For $i = 0 To UBound($Removal) - 1
                    $Cleaner = StringReplace($FuckedUp2, $Removal[$i], "")
                    $FuckedUp2 = $Cleaner
                Next

                $Cleaner = StringReplace($FuckedUp2, "0", "o")

                Local $StringLength = StringLen($Cleaner)
                Local $StringPass = SpecialCharCheck($Cleaner)

                If $StringLength > 5 And $StringLength < 8 And $StringPass = 1 Then
                    Sleep(250)
                    MouseClick("left", 614, 494)
                    Sleep(250)
                    Send($Cleaner, 1)
                    Sleep(500)
                    MouseClick("left", 543, 540)
                    Sleep(250)
                EndIf

 

That helps?

 

Edited by Scorpys
Link to comment
Share on other sites

  • Developers
4 minutes ago, Scorpys said:

That helps?

I understand what you wanted in general, but it really helps your case when you post a runnable script that shows what you are doing. 
The posted script doesn't and I am happy to help but not so much trying to make a demo script for you. ;) 

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Your friend will be StringRegexpReplace. Up to you to read up how this can serve your needs.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

4 minutes ago, Jos said:

I understand what you wanted in general, but it really helps your case when you post a runnable script that shows what you are doing. 
The posted script doesn't and I am happy to help but not so much trying to make a demo script for you. ;) 

You just love torturing me don't you? That's okay, I still love you :D

But even if I posted my entire script, you'd just find more and more problems, and more problems, and would never address my very simple question.

You couldn't really "use" my entire script. It focuses a Firefox browser when a certain keyword appears in the title, then it runs a command, then it filters things out before copying some stuff over from one file to another.

I think I shared enough code and a good enough explanation for you to help me, but okay, it's cool, sit on your high horse and enjoy :D

Link to comment
Share on other sites

12 minutes ago, Jos said:

I understand what you wanted in general, but it really helps your case when you post a runnable script that shows what you are doing. 
The posted script doesn't and I am happy to help but not so much trying to make a demo script for you. ;) 

Okay, here you go:

#include <StringConstants.au3>
#include <MsgBoxConstants.au3>

$SEARCH_TERM = 'keyword' ;
$DELAY = 1000 ; in ms, delay between searches. It can be reduced, but best to not overdo it.

$prevWins = WinList("[CLASS:MozillaWindowClass]") ;

While(True)
    search()   ;
    Sleep($DELAY)   ;

WEnd

Func getPreviousTitleFromHandle($hnd)
    For $i = 1 To $prevWins[0][0]

        $title = $prevWins[$i][0]  ;
        $handle = $prevWins[$i][1]  ;
        If($handle == $hnd) Then
            Return $title ;
        EndIf
    Next


    Return ""   ;
EndFunc   ;==>getPreviousTitleFromHandle

Func search()

    $wins = WinList("[CLASS:MozillaWindowClass]")   ;
    For $i = 1 To $wins[0][0]
        ; get window title
        $title = $wins[$i][0]  ;
        If(StringInStr($title, $SEARCH_TERM) <> 0) Then
            $handle = $wins[$i][1] ;

            ; found pinterest mozilla window
            ;ConsoleWrite('FOUND! ' & $title & @CRLF);
            $prevTitle = getPreviousTitleFromHandle($handle) ;
            If(StringInStr($prevTitle, $SEARCH_TERM) == 0) Then
                ; previous title doesn't have keyword - means navigation took place

                WinActivate($handle) ;



                Local $SomeFileLocation = @ScriptDir & "\result.txt"

                Local $FuckedUpString = FileRead($SomeFileLocation)
                Local $FuckedUpString1 = StringTrimRight($FuckedUpString, 0)

                Sleep(500)

                Local $FuckedUp2 = $FuckedUpString1
                Local $Cleaner

                Local $Removal[41]
                $Removal[0] = "-"
                $Removal[1] = "_"
                $Removal[2] = "."
                $Removal[3] = ","
                $Removal[4] = "‘"
                $Removal[5] = " "
                $Removal[6] = "|"
                $Removal[7] = "—"
                $Removal[8] = "~"
                $Removal[9] = ":"
                $Removal[10] = ";"
                $Removal[11] = "("
                $Removal[12] = ")"
                $Removal[13] = "§"
                $Removal[14] = "©"
                $Removal[15] = "{"
                $Removal[16] = "}"
                $Removal[17] = "¥"
                $Removal[18] = "é"
                $Removal[19] = "*"
                $Removal[20] = "/"
                $Removal[21] = "\"
                $Removal[22] = "°"
                $Removal[23] = "'"
                $Removal[24] = "@"
                $Removal[25] = "!"
                $Removal[26] = """"
                $Removal[27] = "]"
                $Removal[28] = "["
                $Removal[29] = "="
                $Removal[30] = "»"
                $Removal[31] = "«"
                $Removal[32] = "“"
                $Removal[33] = "”"
                $Removal[34] = "£"
                $Removal[35] = "$"
                $Removal[36] = "?"
                $Removal[37] = "i"
                $Removal[38] = "I"
                $Removal[39] = "1"
                $Removal[40] = "l"

                For $i = 0 To UBound($Removal) - 1
                    $Cleaner = StringReplace($FuckedUp2, $Removal[$i], "")
                    $FuckedUp2 = $Cleaner
                Next

                $Cleaner = StringReplace($FuckedUp2, "0", "o")

                Local $StringLength = StringLen($Cleaner)
                Local $StringPass = SpecialCharCheck($Cleaner)

                If $StringLength > 5 And $StringLength < 8 And $StringPass = 1 Then
                    Sleep(250)
                    MouseClick("left", 614, 494)
                    Sleep(250)
                    Send($Cleaner, 1)
                    Sleep(500)
                    MouseClick("left", 543, 540)
                    Sleep(250)
                EndIf

                Sleep(12000)



                $WinTitle = 'Mozilla Crash Reporter'

                If WinExists($WinTitle) Then
                    ProcessClose(WinGetProcess($WinTitle))
                EndIf

                Sleep(18000)



                $prevWins = $wins ;
                Return ;
            EndIf
        EndIf
    Next

    $prevWins = $wins   ;
EndFunc   ;==>search






Func SpecialCharCheck($string)

    Local $ReturnValue = 1

    Local $SpecialCharacterCheck[2]
    $SpecialCharacterCheck[0] = "#"
    $SpecialCharacterCheck[1] = "%"

    Local $HowMany = 0

    Local $RegExp = 0
    For $i = 0 To UBound($SpecialCharacterCheck) - 1
        If StringInStr($string, $SpecialCharacterCheck[$i]) <> 0 Then
            $RegExp = StringRegExp($string, $SpecialCharacterCheck[$i], $STR_REGEXPARRAYGLOBALMATCH)
            If IsArray($RegExp) Then
                If UBound($RegExp) > 1 Then
                    $ReturnValue = 0
                EndIf
                If UBound($RegExp) = 1 Then
                    $HowMany += 1
                EndIf
            EndIf
        EndIf
        $RegExp = 0
    Next

    If $HowMany > 1 Then $ReturnValue = 0

    Return $ReturnValue

EndFunc

Now please, tell me the new problem that you see, that I don't see? Tell me why you can't help me now? :D

Edited by Scorpys
Link to comment
Share on other sites

  • Developers

So when I now copy and paste your posted script I will see the issue?  (don't think so )
Is it really that hard to dumb this down so people can help you implementing in your own code? 

Here's what I was looking for as basis with the incorporated possible solution to study:

Local $Removal[5]
$Removal[0] = "-"
$Removal[1] = "_"
$Removal[2] = "."
$Removal[3] = ","
$Removal[4] = "l"
$WrongString = " this is a example-_.,lL"
$CleanedString = $WrongString
For $i = 0 To UBound($Removal) - 1
    $CleanedString = StringRegExpReplace($CleanedString, "[" & $Removal[$i] & "]" , "")
Next
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $WrongString = ' & $WrongString & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $CleanedString = ' & $CleanedString & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

Jos :)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

1 minute ago, Jos said:

So when I now copy and paste your posted script I will see the issue?  (don't think so )
Is it really that hard to dumb this down so people can help you implementing in your own code? 

Here's what I was looking for as basis with the incorporated possible solution to study:

Local $Removal[5]
$Removal[0] = "-"
$Removal[1] = "_"
$Removal[2] = "."
$Removal[3] = ","
$Removal[4] = "l"
$WrongString = " this is a example-_.,lL"
$CleanedString = $WrongString
For $i = 0 To UBound($Removal) - 1
    $CleanedString = StringRegExpReplace($CleanedString, "[" & $Removal[$i] & "]" , "")
Next
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $WrongString = ' & $WrongString & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $CleanedString = ' & $CleanedString & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

Jos :)

 

Well no. I don't really have the skills to dumb it down. I guess some text could be hardcoded in the script, and then you run the script and it runs the text through the filter, and then pastes the result on the other end. But you would still need it to be pasted somewhere on your computer, like a in a text file. Or maybe the script could create the text file.

Sounds too far fetched and invasive. I couldn't subject strangers to that 😛

Okay, well, seems too complicated to implement. I thought I could force it to be case-sensitive, maybe by doing something like this:

Local $Removal[5]
                $Removal[0] = "-"
                $Removal[1] = "_"
                $Removal[2] = "."
                $Removal[3] = ","
                $Removal[4] = ""l""

Or like this:

Local $Removal[5]
                $Removal[0] = "-"
                $Removal[1] = "_"
                $Removal[2] = "."
                $Removal[3] = ","
                $Removal[4] = "'l'"

But it seems rocket science will be required.

Anyway, thanks for taking the time to reply and everything. Have a nice day :)

Link to comment
Share on other sites

Even simpler than @Jos:

Local $Removal = "-_.,l%§"
Local $WrongString = " this is _an_ example-_.,lL and 1 more § added"
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $WrongString = ' & $WrongString & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
Local $CleanedString = StringRegExpReplace($WrongString, "[" & $Removal & "]" , "")
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $CleanedString = ' & $CleanedString & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

 

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

  • Developers
1 minute ago, Scorpys said:

Well no. I don't really have the skills to dumb it down.

That is BS and you know it. ;) 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

48 minutes ago, jchd said:

Even simpler than @Jos:

Local $Removal = "-_.,l%§"
Local $WrongString = " this is _an_ example-_.,lL and 1 more § added"
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $WrongString = ' & $WrongString & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
Local $CleanedString = StringRegExpReplace($WrongString, "[" & $Removal & "]" , "")
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $CleanedString = ' & $CleanedString & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

 

Thanks man. But it's too complicated for me :)

46 minutes ago, Jos said:

That is BS and you know it. ;) 

Aww, I knew you loved me as much as I love you :D

Anyway guys, since I couldn't solve it with AutoIT, I looked at the process that creates the text that I'm copying, and I blacklisted the lower L there. So, problem solved :)

🤠

Link to comment
Share on other sites

@Scorpys you mention StringReplace in one of your post, so you seem to get used to it.
Why not simply use its 5th parameter to make the replacements case sensitive ?

#include <StringConstants.au3>

Local $sString = StringReplace("lower lower Large Large", "l", "", 0, $STR_CASESENSE)
Local $iReplacements = @extended
MsgBox(0, "", $iReplacements & " replacements were made and the new string is:" & @CRLF & @CRLF & $sString)

Output :

ower ower Large Large

 

Edited by pixelsearch
typo
Link to comment
Share on other sites

12 hours ago, pixelsearch said:

@Scorpys you mention StringReplace in one of your post, so you seem to get used to it.
Why not simply use its 5th parameter to make the replacements case sensitive ?

#include <StringConstants.au3>

Local $sString = StringReplace("lower lower Large Large", "l", "", 0, $STR_CASESENSE)
Local $iReplacements = @extended
MsgBox(0, "", $iReplacements & " replacements were made and the new string is:" & @CRLF & @CRLF & $sString)

Output :

ower ower Large Large

 

Thanks man. I already solved my issue in another way, not with AutoIT.

But this will help if needed again, thanks :)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...