Replace using variable not working
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Replace using variable not working
I'm trying to use replace with a variable, as this:
replace cb with "stuff" in fileContent
cb is a variable containing a block of text taken from fileContent, I'm trying to replace that block with other stuff in the variable fileContent.
But I'm getting this error: stack "main": execution error at line 119 (replace: error in pattern expression), char 1
It works if I put some text, replace "text" with "other text" in fileContent, just not with a variable
replace cb with "stuff" in fileContent
cb is a variable containing a block of text taken from fileContent, I'm trying to replace that block with other stuff in the variable fileContent.
But I'm getting this error: stack "main": execution error at line 119 (replace: error in pattern expression), char 1
It works if I put some text, replace "text" with "other text" in fileContent, just not with a variable
Marcus
Re: Replace using variable not working
Hi Marcus,
I tested this
and it works for me
Best regards
Jean-Marc
I tested this
Code: Select all
on mouseUp
answer file "open"
if it = empty then exit mouseup
put url("file:" & it) into tContent
put tContent into z
put line 1 to 10 of tContent into tReplace
replace tReplace with "stuff" in tContent
put z & cr & cr & tContent
end mouseUp
Best regards
Jean-Marc
https://alternatic.ch
Re: Replace using variable not working
Very strange.
Your result is the behavior I expect, I'll keep digging, maybe I'm doing something odd somewhere else
Your result is the behavior I expect, I'll keep digging, maybe I'm doing something odd somewhere else
Marcus
Re: Replace using variable not working
The first question is what data is contained in the cb variable?
Is it text? If yes, are you sure?
What happens if you "put cb" before the attempt to replace?
Is it text? If yes, are you sure?
What happens if you "put cb" before the attempt to replace?
Re: Replace using variable not working
Sparkout's point is probably the hint
"(replace: error in pattern expression)" sound like as some special chars are in your cb variable
"(replace: error in pattern expression)" sound like as some special chars are in your cb variable
https://alternatic.ch
Re: Replace using variable not working
Well, it does contain at least newlines and tabs, I'll test more and let you know how it goes
Marcus