删除数据指定字段(再问)
str=随机,随机,随机,随机,随机
例
str=2,2,3,2,6,7,你好,9
我假设都把他们全部编号,我如何删除指定的编号的数组.
例如我要删除编号是7的你好,如何删除呢?
str=2(编号),2(编号),3(编号),3(编号),6(编号),7(编号),你好(编号),9(编号)
str=2(1),2(2),3(3),3(4),6(5),7(6),你好(7),9(8)
变成str=2,2,3,3,6,7,9
又或者删除编号是8的那个字段"9"
变成str=2,2,3,3,6,7,你好
又或者删除编号是1的字段"2"
变成str=2,3,2,6,7,你好,9
[解决办法]
给我的感觉就是一个链表的数据结构啊,给你贴个看看
public class tt {
public static void main(String[] args) {
List<String> str = new LinkedList<String>();
str.add("2");
str.add("2");
str.add("3");
str.add("2");
str.add("6");
str.add("7");
str.add("你好");
str.add("9");
str.remove(2);//默认编号从0开始,删第3个就是str.remove(2)
System.out.println(str);
}
}
str="2,2,3,2,6,7,你好,9"
newstr = del(str, 7, ",")
function del(list, pos, delimeter)
ar = split(list,delimeter)
ar(pos-1)=delimeter
s = join(ar,delimeter)
s = replace(s, delimeter & delimeter, delimeter)
s = replace(s, delimeter & delimeter, delimeter)
del = replace(replace(trim(replace(replace(s," ","[space]"),delimeter," "))," ", delimeter),"[space]"," ")
end function