java split函数没有用,关于java:’$’的split()函数无法正常工作

本问题已经有最佳答案,请猛点这里访问。

我在做一个简单的代码

String splitString ="122$23$56$rt";

for(int i=0;i

System.out.println("I GOT IS ::"+splitString.split("$")[i]);

}

当我像

splitString.split("$")

它给我输出[122$23$56$rt]。

为什么这不是固定在"$"上的?

你在String.split()argument is a Regex的AS和$在Java regex API元字符。therefore,You need to Escape恩:P></

String splitString ="122$23$56$rt";

for(int i=0;i

System.out.println("I GOT IS ::"+splitString.split("\\$")[i]);

}

Java regex APIby the other元字符是:负载P></

split(Pattern.quote("$"))

是我最喜欢的。P></

Pattern#quote:欧洲经济区P></

Returns a literal pattern String for the specified String.

你的代码不工作,因为有特别的意义$在正则表达式和正则表达式,因为String#split以As an argument is not,the $interpreted字符串"$"as the,but as the special character $元。P></

不知道那个!桑克斯

逃避它。方法:以茶split()split("\\$")regexP></

试着这样的东西P></

String splitString ="122$23$56$rt";

for(int i=0;i

System.out.println("I GOT IS ::"+splitString.split("$")[i]);

}

注:split()uses在正则表达式。P></

你的正则表达式特殊字符$uses在IEP></

正则表达式$for"is the end of在线"。P></

String splitString ="122$23$56$rt";

for(int i=0;i

System.out.println("Now you GOT this ::"+split(Pattern.quote("$")));

}

there are with the characters 12表示的意义是:反斜杠 caret预热器,the,the sign or the美元美元,周期点,酒吧或管。| the vertical象征的问题,马克?星*,the asterisk前加the,the性括号(SIGN +,开放,关闭和开放性括号),方括号([,the opening卷曲的余烬,often called"是这些特殊字符的元字符"。P></

我知道你$as is also metacharacter说知道你不能定义函数使用简单的分裂。虽然你必须使用pattern在这房子。P></

谢谢……P></

+但是请提供答案的解释。

@Marounmaroun:检查我的编辑。不管怎样,还是谢谢你!!

这是一个解释!:)

IT类:P></

split("\\$")

instead of split("$")P></

它将工作,因为不需要输入split()As的regexP></

String splitString ="122$23$56$rt";

for(int i=0;i

System.out.println("I GOT IS ::"+splitString.split("\\$")[i]);

}

String.split(),.replaceAll()are some of the .match(),使用正则表达式模式和方法,知道You should look at the class of the javadoc的模式:P></

如果你将一个字符模式发生to be of the characters,你必须与\\:恩,你的房子在这个分裂的呼叫:.split("\\$")should beP></

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值