0

I'm pulling and setting a section Title variable

<c:set var="sectionTitle" value="${section.sectionTitle}"/>

But the variable can possibly have spaces and apostrophes (single quotes) and I'm using the variable as a class, and the space and apostrophe is breaking the code when either show up, so I would like replace both with an underscore.

<c:set var="search" value="[ ']"/>
<c:set var="replace" value="_"/>
<c:set var="newTitle" value="${fn:replace(sectionTitle, search, replace)}"/>

This is what I have come up with. The reason for this, is that the "newTitle" shows up a lot in the code, and I would rather paste ${newTitle} rather than the full function, plus I can add to the search array if anything else comes up.

Unfortunately, I can not get this to work. The replace function does not replace any of it.

Any suggestions?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Murphy1976
  • 1,415
  • 8
  • 40
  • 88
  • I could close this as duplicate of http://stackoverflow.com/a/10417446, but this feels too much like a [XY-problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). What exactly is it breaking? JavaScript code? If so, then there's a way much better solution for that. – BalusC Oct 28 '15 at 13:50
  • yes, Javascript variables and labels. – Murphy1976 Oct 28 '15 at 13:52
  • As I guessed. There you go. – BalusC Oct 28 '15 at 13:53

0 Answers0