JSF:如何替换“\\”在一个字符串中 [英] JSF: How to replace "\\" in a string
本文介绍了JSF:如何替换“\\”在一个字符串中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有字符串 text \\
,我需要用<替换 \\
code> / 。我尝试了以下表达式:
Suppose I have the string text\\
, I need to replace \\
with /
. I tried the following expression:
/* str = "text\\" */
<h:outputText value="#{fn:replace(str, '\\', '/')}" />
但我总是遇到以下异常:
But I always run into the following exception:
Caused by: java.util.regex.PatternSyntaxException: Unexpected internal error near index 1
\
^
at java.util.regex.Pattern.error(Pattern.java:1924)
at java.util.regex.Pattern.compile(Pattern.java:1671)
at java.util.regex.Pattern.<init>(Pattern.java:1337)
at java.util.regex.Pattern.compile(Pattern.java:1022)
at java.lang.String.replaceAll(String.java:2210)
at com.sun.faces.facelets.tag.jstl.fn.JstlFunction.replace(JstlFunction.java:222)
如果你能给我一个建议,我将非常感激。
I'd be very grateful if you could give me an advice.
更新:根据以下答案,我找到了以下表达式将起作用:
UPDATE: Based on the answers below, I found out that the following expression will work:
<h:outputText value="#{fn:replace(str, '\\\\', '/')}" />
祝你好运,
推荐答案
试试这个(尚未检查....)
Try this (haven't checked....)
<ui:param name="mydouble" value="\\\\"></ui:param>
<ui:param name="mysingle" value="/"></ui:param>
<h:outputText value="#{fn:replace(str, mydouble, mysingle)}" />
这篇关于JSF:如何替换“\\”在一个字符串中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文