在java中按字符串拆分字符串 [英] Split string by char in java
本文介绍了在java中按字符串拆分字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从网上得到一个字符串,如下所示:
I'm getting a string from the web looking like this:
Latest Episode@04x22^Killing Your Number^May/15/2009
然后我需要存储 04x22
,杀死您的号码
和 May / 15/2009
在不同的变量中,但它不起作用。
Then I need to store 04x22
, Killing Your Number
and May/15/2009
in diffent variables, but it won't work.
String[] all = inputLine.split("@");
String[] need = all[1].split("^");
show.setNextNr(need[0]);
show.setNextTitle(need[1]);
show.setNextDate(need[2]);
现在它只存储 NextNr
,整个字符串
Now it only stores NextNr
, with the whole string
04x22^Killing Your Number^May/15/2009
有什么问题?
推荐答案
String.split(String regex)
参数是一个regualr表达式, ^
那里有特殊的意义; 锚定到开头
The argument is a regualr expression, and ^
has a special meaning there; "anchor to beginning"
您需要这样做:
String []需要=全部[1] .split(\\ ^);
通过转义 ^
你说我的意思是'^''
By escaping the ^
you're saying "I mean the character '^' "
这篇关于在java中按字符串拆分字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文