Pregunta

I need to replace two texts depending on the same parameter. Is there any way to do this? Here's an example of what I'm trying to do.

 if(params["This_year"] == "1/1/14"){
    this.queryText = this.queryText.replace("/**year**/", "2014") 
    replace("/**Last_year**/, "1/1/13")}

I'm not exactly sure if that last line would actually work. Is there an alternate way of doing this?

¿Fue útil?

Solución

Add a dot in between the two String.replace calls, on the same line, like so:

if(params["This_year"] == "1/1/14"){
    this.queryText = this.queryText.replace("/**year**/", "2014").replace("/**Last_year**/, "1/1/13"); }

The second call will modify the string returned by the first call.

My spider sense tells me that there's probably something about this that can be generalized into an algorithm, but without seeing more examples, it's hard to know what that would be.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top