Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Dr J R Stockton Newsgroups: comp.lang.javascript Subject: Re: String Replace. Please, need help. Date: Fri, 14 Oct 2011 21:02:41 +0100 Organization: Home Lines: 23 Message-ID: References: <11174912.1946.1318534920723.JavaMail.geo-discussion-forums@vbmh5> Mime-Version: 1.0 Content-Type: text/plain;charset=us-ascii Injection-Info: mx04.eternal-september.org; posting-host="UwYDIHu13GPq28RciNoAJA"; logging-data="11788"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19mdAht28sUNvFb5CTykD8ESvPN/Ejgx5U=" User-Agent: Turnpike/6.05-S () Cancel-Lock: sha1:wzAwTYndkZ9O5P9g6/qyAVeNbjs= Xref: x330-a1.tempe.blueboxinc.net comp.lang.javascript:7404 In comp.lang.javascript message <11174912.1946.1318534920723.JavaMail.ge o-discussion-forums@vbmh5>, Thu, 13 Oct 2011 12:42:00, Shapper. posted: >I am using "replace" as follows: > >content = source.replace("{id}", options.id).replace("{title}", title); > >However "source" might have or not have the strings "{id}" and "{title}". >When it does not have I get an error. >How can I solve this? Use 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 != . -- (c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05. Website - w. FAQish topics, links, acronyms PAS EXE etc. : - see in 00index.htm Dates - miscdate.htm estrdate.htm js-dates.htm pas-time.htm critdate.htm etc.