Frage

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?

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top