Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.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: Sun, 16 Oct 2011 19:30:41 +0100 Organization: Home Lines: 65 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="10220"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19KfoDTfs8Btu8EfeAN2HiWoLKmgPcGR7c=" User-Agent: Turnpike/6.05-S () Cancel-Lock: sha1:cQrPCofkwqrPxiTxSq5GAhd44uY= Xref: x330-a1.tempe.blueboxinc.net comp.lang.javascript:7495 In comp.lang.javascript message , Sat, 15 Oct 2011 09:32:49, Evertjan. posted: >Dr J R Stockton wrote on 14 okt 2011 in comp.lang.javascript: > >> 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 != . > >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. > >as replace() should not give an error, when there is nothing to replace. > >better try: > >alert( content = source.replace("{id}", options.id) ); >alert( content = X.replace("{title}", title) ); > >I suspect the error won't show till after ok-ing the alerts. You appear to be assuming that you, a Netherlander who is pretty good at understanding and writing proper English, has perfectly understood the intended meaning of what has been written by someone who seems to be an Iberian, or possibly an American. A smart Iberian would have posted bilingually, in good Iberian and in English - many of us here are, as you exemplify, not monoglots. In particular, we do not know for certain whether the OP got an error message for that code from the script engine, or an error message from the script engine later on, or an error report from some sort of checking later on. The OP should have given the exact error message, and enough code to reproduce the problem, and the input used, and the outputs obtained and desired.. The OP should also have said which browser(s) and which OS were in use, just in case it matters. Perhaps the OP had not read , which is UP. -- (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.