gpt4 book ai didi

java分隔符错误

转载 作者:行者123 更新时间:2023-12-01 07:34:58 24 4
gpt4 key购买 nike

我想在字符串中分隔“/*”:

例如

String str="6666 /* 555 / 777 * ttt";

// And result should be
result= 6666 , 555 / 777 * ttt

我用

编写了程序
String[] line_split=line_str.split("/*");

我收到此错误:

Exception in thread "main" java.util.regex.PatternSyntaxException: Dangling meta character '*' near index 0 *

有人可以帮我解决吗?

最佳答案

String.split使用Regex进行分割。 *Regex 中的元字符,具有特殊含义 - 匹配其前面的模式的 0 或多个

你需要转义:-

String[] line_split=line_str.split("/\\*");

关于java分隔符错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13277211/

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