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!
Fastest way to replace text?
Re: Fastest way to replace text?
StringReplace is faster than RegExReplace.
Re: Fastest way to replace text?
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?
Re: Fastest way to replace text?
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:
- 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!!
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
}
Thanks a lot!!
Re: Fastest way to replace text?
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.
Re: Fastest way to replace text?
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.
Re: Fastest way to replace text?
If the text contains more than 256 characters the variable will be to long.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.
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.
Re: Fastest way to replace text?
Variable names are limited to 253 chars but variable contents are not. variable_name := "variable content"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: # _ @ $
Re: Fastest way to replace text?
I routinely use StringReplace with variables that contain thousands of characters.
Re: Fastest way to replace text?
Thank you guys. I will try what boiler said first. I can't post the code, it is way too long.