Fastest way to replace text?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Dorian2
Posts: 5
Joined: 27 Mar 2016, 06:34

Fastest way to replace text?

15 May 2016, 21:56

Hi!
I just started reading about RegEx. I would like to know if it is the fastest way to replace about 500 strings in whole txt files of 0.5GB. Something like:

1) aabbccddee = aa_e
2) bbccddeeff = bb_f
3) wwxxyyzz = w!
4) EwExEyEz = Ew!
5) EwExEy = Ew_y
6) DaDfDhDz = D(afhz)
...
500) abbccddeeffgh = ab_gh

Currently i am using StringReplace, but it takes several minutes :/
Thank you so much for your help!
User avatar
boiler
Posts: 16900
Joined: 21 Dec 2014, 02:44

Re: Fastest way to replace text?

15 May 2016, 23:31

StringReplace is faster than RegExReplace.
gilliduck
Posts: 265
Joined: 06 Oct 2014, 15:01

Re: Fastest way to replace text?

16 May 2016, 00:30

The speed issue you're having may not be with the replacing, it may be with the writing. How are you doing it exactly? Reading the file into memory, replacing all the text, deleting the file, writing the file?
Dorian2
Posts: 5
Joined: 27 Mar 2016, 06:34

Re: Fastest way to replace text?

16 May 2016, 08:28

I am using A_TickCount for both processes.
Right now it takes 4min to read:
- FileRead
- Loop every row, replace some text and make lists of groups

2min:
- Do most of the text replace
- I used this method:

Code: Select all

ListLong = AABBCCDDEE, AABBCCDD, AABBCC, AABB, etc
Loop, Parse, ListLong, `,
   ListLong%A_Index% := A_LoopField

ListShort = A-E, A-D, A-C, A-B, etc
Loop, Parse, ListShort, `,
   ListShort%A_Index% := A_LoopField

Loop, parse, RowsOfText, `n {
  NewRow := A_LoopField
  StringReplace, NewRow , NewRow , ListLong%A_Index%,  ListShort%A_Index%, A
}
- FileAppend: I tried every X rows, and make a whole variable (MonsterVar = % MonsterVar NewText)... Save every X rows gives me a little better result.



Thanks a lot!!
User avatar
rootmos
Posts: 35
Joined: 11 Mar 2016, 04:38
Location: Sweden
Contact:

Re: Fastest way to replace text?

16 May 2016, 08:38

Hi, im not sure if it's faster or not, but im using this lib: https://github.com/hi5/TF
Look at me, I am your god now.
User avatar
boiler
Posts: 16900
Joined: 21 Dec 2014, 02:44

Re: Fastest way to replace text?

16 May 2016, 08:49

Instead of looping, can't you just read it all into one variable and do a StringReplace...All on the whole thing for each piece of text to be replaced? That would be very fast.
User avatar
rootmos
Posts: 35
Joined: 11 Mar 2016, 04:38
Location: Sweden
Contact:

Re: Fastest way to replace text?

16 May 2016, 09:00

boiler wrote:Instead of looping, can't you just read it all into one variable and do a StringReplace...All on the whole thing for each piece of text to be replaced? That would be very fast.
If the text contains more than 256 characters the variable will be to long.

Code: Select all

https://autohotkey.com/docs/Variables.htm
Variable names: Variable names are not case sensitive (for example, CurrentDate is the same as currentdate). Variable names may be up to 253 characters long and may consist of letters, numbers and the following punctuation: # _ @ $
Look at me, I am your god now.
Coco
Posts: 771
Joined: 29 Sep 2013, 20:37
Contact:

Re: Fastest way to replace text?

16 May 2016, 09:37

rootmos wrote:If the text contains more than 256 characters the variable will be to long.

Code: Select all

https://autohotkey.com/docs/Variables.htm
Variable names: Variable names are not case sensitive (for example, CurrentDate is the same as currentdate). Variable names may be up to 253 characters long and may consist of letters, numbers and the following punctuation: # _ @ $
Variable names are limited to 253 chars but variable contents are not. variable_name := "variable content"
guest3456
Posts: 3462
Joined: 09 Oct 2013, 10:31

Re: Fastest way to replace text?

16 May 2016, 09:41

you may want to post your full code and input file

User avatar
boiler
Posts: 16900
Joined: 21 Dec 2014, 02:44

Re: Fastest way to replace text?

16 May 2016, 10:15

I routinely use StringReplace with variables that contain thousands of characters.
Dorian2
Posts: 5
Joined: 27 Mar 2016, 06:34

Re: Fastest way to replace text?

17 May 2016, 21:54

Thank you guys. I will try what boiler said first. I can't post the code, it is way too long.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Rohwedder and 232 guests