Page 1 of 1

Replace using variable not working

Posted: Wed Dec 31, 2014 4:45 pm
by trenatos
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

Re: Replace using variable not working

Posted: Wed Dec 31, 2014 5:10 pm
by jmburnod
Hi Marcus,
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
and it works for me
Best regards
Jean-Marc

Re: Replace using variable not working

Posted: Wed Dec 31, 2014 5:13 pm
by trenatos
Very strange.

Your result is the behavior I expect, I'll keep digging, maybe I'm doing something odd somewhere else

Re: Replace using variable not working

Posted: Wed Dec 31, 2014 5:20 pm
by SparkOut
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?

Re: Replace using variable not working

Posted: Wed Dec 31, 2014 5:43 pm
by jmburnod
Sparkout's point is probably the hint
"(replace: error in pattern expression)" sound like as some special chars are in your cb variable

Re: Replace using variable not working

Posted: Wed Dec 31, 2014 11:26 pm
by trenatos
Well, it does contain at least newlines and tabs, I'll test more and let you know how it goes