【发布时间】:2017-03-28 05:36:55
【问题描述】:
所以我有一个这样的字符串:<em>1234</em>56.70
它基本上是一个数字,em 标签有助于识别字符串中要突出显示的内容
我需要先将字符串转换为具有当前语言环境格式的实际数字。所以我删除了em 标记(用emptyString 替换All),然后使用numberFormat java API 得到一个字符串,如:$123,456.70
问题在于,我丢失了高亮 (em) 标签。所以我需要把它放回格式化的字符串中,像这样:<em>$123,4</em>56.70
highlightValue = "<em>1234</em>56.70";
highlightValue = highlightValue.replaceAll("<em>", "").replaceAll("</em>", ""); // highlightValue is now 123456.70
highlightValue = numberFormat.convertToFormat(highlightValue, currencyCode); // highlightValue is now $123,456.70
highlightValue = someFunction(highlightValue); // this function needs to return <em>$123,4</em>56.70
我不确定使用什么方法。我正在尝试模式匹配,但不知道如何实现它。
感谢所有帮助!
【问题讨论】:
-
输入字符串是否总是以
<em>开头?
标签: java regex string format replaceall