怎么得到新的字符串 比如以前是String str = 12313.jsp,534.jsp,7556.jsp;要删除534.jsp得到新的字符串12313.jsp,7556.jsp哪位知道怎么写啊 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 字符串大概就是 xxx.xxx,yyy.yyy,zzz.zzz这种形式? 写个死的 String str = "12313.jsp,534.jsp,7556.jsp"; String s=str.substring(0,str.indexOf(",")); String spare1=str.substring(str.indexOf(",")+1); String s2=spare1.substring(spare1.indexOf(",")); String s3=s+s2; System.out.println(s3); 要是活动的话 接以“,”号切分字符串用map装起来在删除你想删除的 String str = "12313.jsp,534.jsp,7556.jsp"; System.out.println(str.replaceAll("(?<=,).*,(?!,)","")); 说说规律?每次会出现多少个以“,”分隔的内容?每次删除几个?package com.xuz.csdn.worldcup.day13;public class StringSplitTest { /** * @param args */ public static void main(String[] args) { System.out.println(splitByCount("1.jsp,2.jsp,3.jsp",",",2)); System.out.println(splitByCount("1.jsp,2.jsp,3.jsp",",",2,3)); } private static String splitByCount(String str,String regex,int...nums){ StringBuffer sb = new StringBuffer(); String[] array = str.split(regex); for (int i = 0; i < array.length; i++) { if (isContains(nums, i+1) == false) { sb.append(array[i]+","); } } String temp = sb.toString(); return temp.substring(0,temp.length()-1); } private static boolean isContains(int[] sour,int i){ for (int j = 0; j < sour.length; j++) { if (sour[j] == i) { return true; } } return false; }} private static boolean isContains(int[] sour,int i){ for (int j = 0; j < sour.length; j++) { if (sour[j] == i) { return true; } } return false; }int[] -> List 然后用contains方法亦可。 string str = "12313.jsp,534.jsp,7556.jsp"; string[] s= str.Split(','); string ss=""; if (str.Contains("534.jsp")) { for (int i = 0; i < s.Length; i++) { if (s[i] != "534.jsp") { if (i != s.Length - 1) { ss+=s[i]+","; } else { ss += s[i]; } } } } package com;import java.util.regex.Matcher;import java.util.regex.Pattern;public class Test { public static void main(String[] args) { String str = "12313.jsp,534.jsp,7556.jsp"; Matcher matcher = Pattern.compile("(\\S{10})\\S{8}(\\S+)").matcher(str); while (matcher.find()) { System.out.println(matcher.group(1) + matcher.group(2)); } }} public static void main(String[] args) { // 方法1:根据完整名字删除 String str = "12313.jsp,534.jsp,7556.jsp"; String delStr = "534.jsp"; str = str.replaceAll(delStr + ",", "");// 12313.jsp,7556.jsp System.out.println(str); // 方法2:根据模糊字段删除 String str2 = "12313.jsp,534.jsp,7556.jsp"; String delStr2 = "4.js"; str2 = str2.replaceAll(",?\\w*"+delStr2+"\\w*\\.?\\w*,?", ","); // 12313.jsp,7556.jsp System.out.println(str2); } str.split(",");循环数组,删除下标为1的数据 public static void main(String args[]){ System.out.println(DeleteWord.delete("1.jsp,2.jsp,3.jsp,3.jsp,3.jsp,777.jsp,3.jsp", "3.jsp")); } public static String delete(String orginal,String target){ StringBuffer result =new StringBuffer(); String array[]=orginal.split(","); for(int i = 0;i<array.length;i++){ if(!array[i].equals(target)){ result.append(array[i]); result.append(","); } } return result.toString(); } 附件保存,独立文件还是数据库BLOB WebService SAAJ 未将对象引用设置到对象的实例.急 , 在线等... getParamament()和getAttriubutiue()的区别 Struts2 <s:checkboxlist/> 标签的问题,高手帮忙呀! 菜鸟来提问 TOMCAT小问题 现在要用hibernate连接两个数据库(都是ORACLE),一个本地,一个远程的 第2个问题 JBuilder 怎么老是自动关闭 有任用过axis吗? tomcat在马上要启动完成的时候为什么又要重新启动一次? 关于多条update语句的效率问题.
String s=str.substring(0,str.indexOf(","));
String spare1=str.substring(str.indexOf(",")+1);
String s2=spare1.substring(spare1.indexOf(","));
String s3=s+s2;
System.out.println(s3);
String str = "12313.jsp,534.jsp,7556.jsp";
System.out.println(str.replaceAll("(?<=,).*,(?!,)",""));
* @param args
*/
public static void main(String[] args) {
System.out.println(splitByCount("1.jsp,2.jsp,3.jsp",",",2));
System.out.println(splitByCount("1.jsp,2.jsp,3.jsp",",",2,3));
} private static String splitByCount(String str,String regex,int...nums){
StringBuffer sb = new StringBuffer();
String[] array = str.split(regex);
for (int i = 0; i < array.length; i++) {
if (isContains(nums, i+1) == false) {
sb.append(array[i]+",");
}
}
String temp = sb.toString();
return temp.substring(0,temp.length()-1);
}
private static boolean isContains(int[] sour,int i){
for (int j = 0; j < sour.length; j++) {
if (sour[j] == i) {
return true;
}
}
return false;
}
}
for (int j = 0; j < sour.length; j++) {
if (sour[j] == i) {
return true;
}
}
return false;
}
int[] -> List 然后用contains方法亦可。
string[] s= str.Split(',');
string ss="";
if (str.Contains("534.jsp"))
{
for (int i = 0; i < s.Length; i++)
{
if (s[i] != "534.jsp")
{
if (i != s.Length - 1)
{
ss+=s[i]+",";
}
else
{
ss += s[i];
}
}
}
}
package com;import java.util.regex.Matcher;
import java.util.regex.Pattern;public class Test {
public static void main(String[] args) {
String str = "12313.jsp,534.jsp,7556.jsp";
Matcher matcher = Pattern.compile("(\\S{10})\\S{8}(\\S+)").matcher(str);
while (matcher.find()) {
System.out.println(matcher.group(1) + matcher.group(2));
}
}}
public static void main(String[] args) {
// 方法1:根据完整名字删除
String str = "12313.jsp,534.jsp,7556.jsp";
String delStr = "534.jsp";
str = str.replaceAll(delStr + ",", "");// 12313.jsp,7556.jsp
System.out.println(str);
// 方法2:根据模糊字段删除
String str2 = "12313.jsp,534.jsp,7556.jsp";
String delStr2 = "4.js";
str2 = str2.replaceAll(",?\\w*"+delStr2+"\\w*\\.?\\w*,?", ","); // 12313.jsp,7556.jsp
System.out.println(str2);
}
System.out.println(DeleteWord.delete("1.jsp,2.jsp,3.jsp,3.jsp,3.jsp,777.jsp,3.jsp", "3.jsp"));
}
public static String delete(String orginal,String target){
StringBuffer result =new StringBuffer();
String array[]=orginal.split(",");
for(int i = 0;i<array.length;i++){
if(!array[i].equals(target)){
result.append(array[i]);
result.append(",");
}
}
return result.toString();
}