gpt4 book ai didi

java - 去掉java字符串中括号外的所有内容

转载 作者:行者123 更新时间:2023-12-01 08:07:33 27 4
gpt4 key购买 nike

我有以下字符串

34rf;43jh<helloworld>guge73g34/

我基本上希望从字符串中删除“<”和“>”之外的所有内容,以便它返回:

<helloworld>

我怎样才能做到这一点?

最佳答案

我有一些建议,我可能会做这样的事情

public static String parse(String in) {
// Find the open '<'.
int p1 = in.indexOf('<');
// If we found an open less-then, check for next closing greater-then
int p2 = (p1 < 0) ? -1 : in.indexOf('>', p1 + 1);
if (p2 >= 0) {
// Found it... return the sub-string.
return in.substring(p1, p2 + 1);
}
// return the input? might want "" instead.
return in;
}

关于java - 去掉java字符串中括号外的所有内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20277223/

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