【发布时间】:2011-12-09 06:20:51
【问题描述】:
我需要从字符串数组中删除';'。有什么解决办法吗?
我在课堂上所做的是检索一段没有空格连接的长字符串
(thisisalongpieceofstringtobeseparated)
我通过在它们之间插入';' 来分隔它们
(this;is;a;long;piece;of;string;to;be;separated;)
然后我使用.split(";") 将它们添加到数组中。一切都成功了,但最后一个索引是';'。
this
is
a
long
piece
of
string
to
be
separated;
需要去掉最后一个;
根据要求,代码如下。
while (line != null) {
if(line.contains("../../"))
{
int startIndex = line.indexOf("../../") + 6;
int endIndex = line.indexOf(">", startIndex + 1);
String abc = "http://www.google.com/";
String imageSrc = line.substring(startIndex,endIndex);
//complete full url
String xyz = abc +imageSrc;
xyz = xyz.substring(0,xyz.indexOf('"'));
xyz = xyz +";";
content += xyz;
mStrings = content.split(";");
【问题讨论】:
-
首先我会更容易生成正确序列化的字符串。例如:
(a;b;c)而不是(a;b;c;) -
你能给我们看看代码吗?我无法使用 String.split 重现您的问题
-
@Hend:发布您的代码。你在代码的其他地方有问题。
-
好的,我已经在代码中添加了。请帮帮我。非常感谢