Posts: 34
Threads: 14
Joined: Feb 2017
Hello!
can anybody help me with QM?
I need to replace (without open file click on menu...) the text in the file of notepad
I have text:
1=
9,800
2=
9,500
need text:
Bom 9,800 bibom
Mango 9,500 tango
Posts: 12,072
Threads: 140
Joined: Dec 2002
Macro
Macro2865
str filePath="Q:\test\test.txt"
str fileText.getfile(filePath)
str oldText=
;1=
;9,800
;2=
;9,500
str newText=
;Bom 9,800 bibom
;Mango 9,500 tango
int n=fileText.findreplace(oldText newText 2) ;;see also replacerx
out F"Replaced {n} instances"
if(n) fileText.setfile(filePath)
Posts: 34
Threads: 14
Joined: Feb 2017
You help me with my programm. I can't thank you enough for your help.
I have allowed inaccuracy in a task. digits 9,800 and 9,500 are always different, I don't know with what they will be next time. how to make them a variable?
int G1 G2 ={any text}
str filePath="Q:\test\test.txt"
str fileText.getfile(filePath)
str oldText=
;1=
;G1
;2=
;G2
str newText=
;Bom G1 bibom
;Mango G2 tango
int n=fileText.findreplace(oldText newText 2) ;;see also replacerx
out F"Replaced {n} instances"
if(n) fileText.setfile(filePath)
something like that.....
Posts: 12,072
Threads: 140
Joined: Dec 2002
Macro
Macro2840
str G1="9,800"
str G2="9,500"
str filePath="Q:\test\test.txt"
str fileText.getfile(filePath)
str oldText=
F
;1=
;{G1}
;2=
;{G2}
str newText=
F
;Bom {G1} bibom
;Mango {G2} tango
int n=fileText.findreplace(oldText newText 2) ;;see also replacerx
out F"Replaced {n} instances"
if(n) fileText.setfile(filePath)
Posts: 34
Threads: 14
Joined: Feb 2017
Numbers 9.800 and 9,500 is only for example
(( it is can be any numbers... 568 or 12 or 44444... always different numbers... in your code unfortunately I depend of numbers 9.800 and 9.500
You very much would help me having changed this situation
Posts: 12,072
Threads: 140
Joined: Dec 2002
Quote:int G1 G2 ={any text}
I just replaced int to str. Does it have to be int and not str?
if G1 and G2 values are always different, how the macro gets these values?
Posts: 34
Threads: 14
Joined: Feb 2017
Gintaras Wrote:Quote:int G1 G2 ={any text}
I just replaced int to str. Does it have to be int and not str?
if G1 and G2 values are always different, how the macro gets these values?
I think it can be done by lines, to cut second line and pust it in first line. words "bom" and "bibom" constant words
Posts: 12,072
Threads: 140
Joined: Dec 2002
It seems you can use replacerx instead of findreplace. And let oldText and newText be regular expressions. But then why there are variables G1 and G2?
Posts: 34
Threads: 14
Joined: Feb 2017
Gintaras Wrote:It seems you can use replacerx instead of findreplace. And let oldText and newText be regular expressions. But then why there are variables G1 and G2?
I don't know the man, I don't know, I just am under construction to understand
Posts: 12,072
Threads: 140
Joined: Dec 2002
Macro
Macro2865
str fileText=
;...
;1=
;9,800
;2=
;9,500
;...
str oldText=
;(?m)^1=
;([\d,]+)
;2=
;([\d,]+)$
str newText=
;Bom $1 bibom
;Mango $2 tango
int n=fileText.replacerx(oldText newText)
out F"Replaced {n} instances"
out fileText