Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSTL: fn:replace method -- need to replace more than one substring...  RSS feed

 
maya brown
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

hi,

in specs for fn:replace method (http://java.sun.com/products/jsp/jstl/1.1/docs/tlddocs/index.html -- can't post link to replace() method -- "no frames" link isn't working..) it says:

${fn:replace(text, "-", "•")}

but I need to replace TWO chars in a string... I need to replace all occurrences of '_' AND all occurrences of '.' with an empty space; how would I do that?

thank you very much..


 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Call it twice.

Or write your own EL method to do it.
 
maya brown
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

thank you very much..

so can I call it twice in a stmt like this?

${fn:toLowerCase(fn:replace(Prod, ' ', '_'))}

I mean thus?

${fn:toLowerCase(fn:replace(Prod, ' ', '_'));fn:replace(Prod, ' ', '.')) }


thank you....
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How would you do it in Java, or any other language?
 
maya brown
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


oh -- in Java or JSP scriptlet I would know very easily how to do this (declare/init String var., then massage it with the methods..) but this is for work, everything is done in JSTL and I don't think they want me to use scriptlets.. actually entire stmt is something like:

<c:set var="linkToProd"></c:set>

(
element is closed a several lines down.. after more stmts..)

I just need to also replace any occurring '.' with an empty space..


thank you..

  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And yet, you already have an example of calling two functions: toLowercase and replace. Why would two calls to replace be any different?
 
maya brown
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


oh brother, why doesn't all my code appear?

what I meant:

<c:set var="linkToProd"><a > </c:set> <br /> <br /> oh brother, this is tedious.. don't know if it will display correctly now or not.. I have been criticized here before for not using.. what is it? BB code? don't know how to use it.. so HTML is no longer allowed? I don't get this.. <br /> <br /> thank you.. <br /> <br /> rel="nofollow">
 
maya brown
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
maya brown wrote:

oh brother, why doesn't all my code appear?

what I meant:

<c:set var="linkToProd"><a > </c:set> <br /> <br /> oh brother, this is tedious.. don't know if it will display correctly now or not.. I have been criticized here before for not using.. what is it? BB code? don't know how to use it.. so HTML is no longer allowed? I don't get this.. <br /> <br /> ok, one more try: <br /> <br /> <c:set ><a ></c:set> <br /> <br /> <br /> <br /> <br /> <br /> thank you.. <br /> <br /> rel="nofollow">
 
maya brown
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

my code I want to display (it's a long line of code..) is not displaying.. I don't know what the problem is.. I would post a screenshot of it, but I don't have access to my personal FTP server from here..

oh brother..

oh well..


 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to use code tags is explained here.

When posting HTML, be sure to click the "Disable HTML in this message" checkbox.
 
maya brown
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


ok, thank you very much.. let me try again, then:



thank you..

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!