去掉String中不想要的部分 String str= "N=22539 100016&Nty=1&Ntk=product_rank1&Ntt=&Ntx=mode matchallpartial";去掉"N=22539 100016&",即参数"N",N 的值和分隔符"&".怎么去掉,谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Nty=1&Ntk=product_rank1&Ntt=&Ntx=mode matchallpartial你想要的结果是这个吗? I don't know what the style of all the strings, but the code can be used for your example...String[] strArray = str.split("&");String output = "";for (int i=1; i<strArray.length; i++) output += strArray[i]; 对的,就要“Nty=1&Ntk=product_rank1&Ntt=&Ntx=mode matchallpartial ”。replace()不见效阿:(其实可以把用连接的方法,可以觉得太笨了 :) 谢谢justinavril,是的可以这样做,可是还有更简单的办法吗? String str= "N=22539 100016&Nty=1&Ntk=product_rank1&Ntt=&Ntx=mode matchallpartial";str = str.replaceAll("N=([^&]*)&?", "");System.out.println(str); public class Test1 { public static void main(String[] args) { String str= "N=22539 100016&Nty=1&Ntk=product_rank1&Ntt=&Ntx=mode matchallpartial"; str = str.replaceAll("N=[^&]*&", ""); System.out.println(str); }} int index = str.indexOf("&");String newStr = str.substring(index + 1); public class test { public static void main(String[] args) { String str= "N=22539 100016&Nty=1&Ntk=product_rank1&Ntt=&Ntx=mode matchallpartial"; String str2 = str.replace("N=22539 100016", ""); System.out.println(str); System.out.println(str2); }}打印的结果:N=22539 100016&Nty=1&Ntk=product_rank1&Ntt=&Ntx=mode matchallpartial&Nty=1&Ntk=product_rank1&Ntt=&Ntx=mode matchallpartial String str2 = str.replace("N=22539 100016&", ""); return str.replace("N=([^&]*)&?", ""); public class TString { public static void main(String[] args) { String str = "N=22539 100016&Nty=1&Ntk=product_rank1&Ntt=&Ntx=mode matchallpartial"; str = str.replaceAll("N=[^N]*", ""); System.out.println(str); }} it's weird ! just now it doesn't work:)非常感谢各位的热情帮助,嗬嗬;我觉得substring 正则表达式最简单,谢谢啦:D 获取第一个 & 所在位置 offsetsubString(offset + 1); 异常问题!!! java mail 带附件 发送 如何清空ByteArrayOutputStream的缓冲区 功课成绩java 大家来看看这几行的小代码~ 主程序非要等子线程死亡才可以退出吗? 最新JBuilder8和各大Server合成的攻略﹐包括WebLogic 7.0, WebSphere 4.0, SUN ONE 6.5等 关于java nio2.0 长连接的问题 kk 通过串口传送一个结构(包括String,和float),请问用java应该怎么作? 怎么实现,记事本的撤销和查找功能? 为什么我这个程序运行后在文本文件里没有写入5个随机数呢
output += strArray[i];
其实可以把用连接的方法,可以觉得太笨了 :)
str = str.replaceAll("N=([^&]*)&?", "");
System.out.println(str);
String str= "N=22539 100016&Nty=1&Ntk=product_rank1&Ntt=&Ntx=mode matchallpartial";
str = str.replaceAll("N=[^&]*&", "");
System.out.println(str);
}
}
String newStr = str.substring(index + 1);
public class test {
public static void main(String[] args) {
String str= "N=22539 100016&Nty=1&Ntk=product_rank1&Ntt=&Ntx=mode matchallpartial";
String str2 = str.replace("N=22539 100016", "");
System.out.println(str);
System.out.println(str2);
}}打印的结果:
N=22539 100016&Nty=1&Ntk=product_rank1&Ntt=&Ntx=mode matchallpartial
&Nty=1&Ntk=product_rank1&Ntt=&Ntx=mode matchallpartial
return str.replace("N=([^&]*)&?", "");
public static void main(String[] args) {
String str = "N=22539 100016&Nty=1&Ntk=product_rank1&Ntt=&Ntx=mode matchallpartial";
str = str.replaceAll("N=[^N]*", "");
System.out.println(str);
}
}
我觉得substring 正则表达式最简单,谢谢啦:D
subString(offset + 1);