Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
to replace the text in the file of a notepad
#1
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
#2
Macro Macro2865
Code:
Copy      Help
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)
#3
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?
Code:
Copy      Help
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.....
#4
Macro Macro2840
Code:
Copy      Help
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)
#5
Numbers 9.800 and 9,500 is only for example Sad(( 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 Sad Sad Sad
You very much would help me having changed this situation
#6
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?
#7
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
#8
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?
#9
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
#10
Macro Macro2865
Code:
Copy      Help
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


Forum Jump:


Users browsing this thread: 1 Guest(s)