Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!news.xs4all.nl!not-for-mail Date: Sat, 15 Oct 2011 11:47:28 +0200 From: Luuk User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:7.0.1) Gecko/20110929 Thunderbird/7.0.1 MIME-Version: 1.0 Newsgroups: comp.lang.javascript Subject: Re: String Replace. Please, need help. References: <11174912.1946.1318534920723.JavaMail.geo-discussion-forums@vbmh5> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Lines: 26 NNTP-Posting-Host: 80.101.116.74 X-Trace: 1318672202 news2.news.xs4all.nl 2442 80.101.116.74:52047 Xref: x330-a1.tempe.blueboxinc.net comp.lang.javascript:7420 On 15-10-2011 11:32, Evertjan. wrote: >> X = source.replace("{id}", options.id) >> > content = X.replace("{title}", title) >> > and then you can test that in each case a change has been made, by >> > comparing the strings with == or != . > Yes, but that would not solve this: > >>> >> However "source" might have or not have >>> >> the strings "{id}" and "{title}". >>> >> When it does not have I get an error. function myReplace(s, t, u) { if s.indexOf(t)>=0 { return s.replace(t,u); } else { return s; } } X = myReplace(source,"{id}", options.id); content = myReplace (X, "{title}", title); -- Luuk