Replace using variable not working

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
trenatos
Posts: 189
Joined: Wed Jul 03, 2013 6:46 am
Contact:

Replace using variable not working

Post by trenatos » Wed Dec 31, 2014 4:45 pm

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
Marcus

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Replace using variable not working

Post by jmburnod » Wed Dec 31, 2014 5:10 pm

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
https://alternatic.ch

trenatos
Posts: 189
Joined: Wed Jul 03, 2013 6:46 am
Contact:

Re: Replace using variable not working

Post by trenatos » Wed Dec 31, 2014 5:13 pm

Very strange.

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

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Re: Replace using variable not working

Post by SparkOut » Wed Dec 31, 2014 5:20 pm

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?

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Replace using variable not working

Post by jmburnod » Wed Dec 31, 2014 5:43 pm

Sparkout's point is probably the hint
"(replace: error in pattern expression)" sound like as some special chars are in your cb variable
https://alternatic.ch

trenatos
Posts: 189
Joined: Wed Jul 03, 2013 6:46 am
Contact:

Re: Replace using variable not working

Post by trenatos » Wed Dec 31, 2014 11:26 pm

Well, it does contain at least newlines and tabs, I'll test more and let you know how it goes
Marcus

Post Reply