Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Search similar strings


Best Answer Jackie Sztuk _Blackholyman , 22 October 2015 - 08:14 AM

Go to the full post »


  • Please log in to reply
6 replies to this topic
radiosilk
  • Members
  • 22 posts
  • Last active: Nov 06 2015 09:10 AM
  • Joined: 27 Sep 2015

I wish to use IfinString and StringReplace to remove a set of strings that are built similarly.

 

Examples of such strings:

a.)  "09JANFUT"

b.)  "16MARFUT"

c.)  "23DECFUT"

etc...

 

The first  characters are numbers. Last three are always "FUT". Middle 3 are alphabets A-Z.

 

Is there a way to define a variable in such a way to make the below code work:

iffut:= xxxxx"FUT"  ; (where x is as described above)

IfInString,dato,%iffut%
StringReplace, dato, dato, %iffut%, , All   


Jackie Sztuk _Blackholyman
  • Spam Officer
  • 3757 posts
  • Last active: Apr 03 2016 08:47 PM
  • Joined: 28 Feb 2012
✓  Best Answer

string =
(
01JANTUT
09JANFUT
16MARFUT
12MAFUT
23DECFUT
445ecFUT
)
 
regex_patten = \d{2}[a-zA-Z]{3}FUT
 
if RegExMatch(string, regex_patten)
newstring := RegExReplace(string, regex_patten, "")
 
msgbox % "old string:`n`n" string "`n`nnew string`n`n" newstring

Helping%20you%20learn%20autohotkey.jpg?d

[AHK] Version. 1.1+ [CLOUD] DropBox ; Copy [WEBSITE] Blog ; About

radiosilk
  • Members
  • 22 posts
  • Last active: Nov 06 2015 09:10 AM
  • Joined: 27 Sep 2015

Wow ! Thanks  a lot, Jackie. You are a genius..

 

Only 2 more things if you could answer.

 

1.  How to understand the pattern you described so that i could create myself in future: 

regex_patten = \d{2}[a-zA-Z]{3}FUT

 

2.  Is there a faster alternative like StringReplace where in directly this pattern can be used ? Because this code analyzes and replaces almost 5000 rows and current solution takes time. (i am a noob.. so may be i am wrong somewhere)

 

please do inform..

 

many thanks again !!



Jackie Sztuk _Blackholyman
  • Spam Officer
  • 3757 posts
  • Last active: Apr 03 2016 08:47 PM
  • Joined: 28 Feb 2012

1. https://regex101.com/r/vM0vA7/1

 

2. RegEx is the way to go if you wish to use patterns for string operations like this... Regex is quite fast and in your case you can simply use the RegExReplace without if statement as there does not seem be a need to check for the pattern first as it will not save much.

 

example:

loop 5000
string .= SubStr(A_index, 1, 2) "JANFUT`n"
 
regex_patten = \d{2}[a-zA-Z]{3}FUT\R
 
starttime := A_TickCount
newstring := RegExReplace(string, regex_patten, "")
endtime := A_TickCount - starttime
 
msgbox % "time:`n`n" endtime "milliseconds`n`nnew string:`n`n" newstring "`n`nold string`n`n" string

Helping%20you%20learn%20autohotkey.jpg?d

[AHK] Version. 1.1+ [CLOUD] DropBox ; Copy [WEBSITE] Blog ; About

space
  • Members
  • 520 posts
  • Last active:
  • Joined: 12 Aug 2014
Don't forget to add SetBatchlines, -1 at the very top of your script. Might help.

radiosilk
  • Members
  • 22 posts
  • Last active: Nov 06 2015 09:10 AM
  • Joined: 27 Sep 2015

Thanks a ton, Jackie. I will try to understand what you have provided by trial and error. Thanks for regex101. Will go through that shortly.

 

Thanks Space. Just found out about SetBatchLines. Going to insert it right away.

 

Thanks both of you..

 

AHK is awesome   :shy:  .. thanks to all the creators, maintainers and innovators !!



bruno
  • Members
  • 635 posts
  • Last active: Nov 04 2015 02:26 PM
  • Joined: 07 Mar 2011

very nice showcase of RegEx performance! ;)