gpt4 book ai didi

Java - 如何从字符串中删除尖括号和文本

转载 作者:行者123 更新时间:2023-11-29 20:07:33 26 4
gpt4 key购买 nike

我想从我的字符串中删除所有出现的尖括号和中间的文本。所以给出以下内容:

<a target="_blank" href="http://en.wikipedia.org/wiki/Grand_Theft_Auto_%28series%29">Grand Theft Auto</a> is a video game series created and primarily developed by Scottish developer Rockstar North, published in 1998.

我需要这个:

Grand Theft Auto is a video game series created and primarily developed by Scottish developer Rockstar North, published in 1998.

我试过使用以下内容,它似乎根本没有改变原始字符串:

string.replaceAll("<.*?>","");

最佳答案

Java 字符串不可变,并且不会自行改变。你需要改变它们。改变这个:

string.replaceAll("<.*?>","");

对此:

string = string.replaceAll("<.*?>","");

关于Java - 如何从字符串中删除尖括号和文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35457909/

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