time of year for most> people so the Christmas> bazaar is a-6ren">
gpt4 book ai didi

java - 如何从java中的字符串中删除>标签

转载 作者:行者123 更新时间:2023-11-30 05:57:55 25 4
gpt4 key购买 nike

我有以下字符串。 "Christmas is a very expensive> time of year for most> people so the <br/>Christmas> bazaar is an <b>opportunity</b> for parents to indulge their offspring and buy lots> of small items> as either presents or <b>stocking fillers</b> .|Trust me, it's not easy scooping up gift votives and <b>stocking stuffers</b>"

现在我只想删除 ">"仅以单词结尾的字符串,而不是 html 标签,例如 "<br/> or <b"

如果我使用String.replace("\\>","")然后它删除所有 >字符串中的标签。
如何实现这一目标?

最佳答案

检查以下代码是否满足您的需要:

    String[] split = "This is test string> <br></br>".split(">");

StringBuilder sb = new StringBuilder();
for (String it : split) {
if(it.contains("<")) {
it += ">";
}

sb.append(it);
}

String result = sb.toString();

关于java - 如何从java中的字符串中删除>标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52841072/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com