龙牌石膏板(1.2*3)水泥压力板(1.2*2.4)石膏板(1.2*3)压力板(1.2*2.4)
解决方案 »
- jsp表单,三个年月日下拉列表~ request接受到了三个参数~分别是年月日~ 怎样把3个参数变成日期型?
- 怎么用cookie来记录用户浏览或回复的帖子?
- 如何实现就不刷新
- 高手请进
- 不懂JSP,请教一个极简单的问题,回复马上给分
- Unable to compile class for JSP 怎么解决啊.
- 请教各位大侠:一个关于传ID的问题!谢谢!
- 请问谁知道那里免费的jsql、jturbo的驱动下载
- struts 购物车小问题session数组 高手进
- shiro在使用redis缓存的时候出现问题-来大佬帮忙看看
- js动态生成的文本框控件怎样传递给服务端
- jsp两个数据库的查询结果集是否能合在一起
var str ="龙牌石膏板(1.2*3)水泥压力板(1.2*2.4)石膏板(1.2*3)压力板(1.2*2.4)"'
str.substring(0,5);//依次截取
然后再Split。
String reg = "[(\\w+\\.\\*)]";
Pattern p = Pattern.compile(reg);
Matcher m = p.matcher(string);
String strTrim = m.replaceAll("");
System.out.println("strTrim========"+strTrim);
得到结果:龙牌石膏板水泥压力板石膏板压力板
public class TestAccess {
public static void main(String args[])
{
String str ="龙牌石膏板(1.2*3)水泥压力板(1.2*2.4)石膏板(1.2*3)压力板(1.2*2.4)";
String s = str.replaceAll("\\([[1-9]d*\\.d*|0\\.d*[1-9]d*$]+\\*[[1-9]d*\\.d*|0\\.d*[1-9]d*$]+\\)", "");
System.out.println("s:" + s);
//结果是: s:龙牌石膏板水泥压力板石膏板压力板
}
}
import org.apache.oro.text.regex.Pattern;
import org.apache.oro.text.regex.PatternCompiler;
import org.apache.oro.text.regex.PatternMatcherInput;
import org.apache.oro.text.regex.Perl5Compiler;
import org.apache.oro.text.regex.Perl5Matcher;public class Test {
private static Perl5Matcher match = new Perl5Matcher(); private static String test = "\\w+(?=([(]|$))"; private static Pattern testPattern; static {
PatternCompiler compiler = new Perl5Compiler();
try {
testPattern = compiler.compile(test);
} catch (MalformedPatternException e) {
e.printStackTrace();
}
} public static String parseOfString(String originalString) {
PatternMatcherInput input = new PatternMatcherInput(originalString);
String afterParse = "";
while (match.contains(input, testPattern)) {
System.out.println(match.getMatch());
afterParse += match.getMatch();
}
return afterParse;
} public static void main(String[] a) {
String originalString = "龙牌石膏板(1.2*3)水泥压力板(1.2*2.4)石膏板(1.2*3)压力板(1.2*2.4)";
System.out.println(parseOfString(originalString));
}
}结果是:
龙牌石膏板
水泥压力板
石膏板
压力板
龙牌石膏板水泥压力板石膏板压力板
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String str="龙牌石膏板(1.2*3)水泥压力板(1.2*2.4)石膏板(1.2*3)压力板(1.2*2.4)";
ArrayList<String> result=new ArrayList<String>();
while(str.length()!=0)
{
int pos=str.indexOf("(");
int pos2=0;
if(pos>=0)
{
String x=str.substring(pos2,pos);
pos2=str.indexOf(")")+1;
if(pos2<=str.length())
{
str=str.substring(pos2,str.length());
}
result.add(x);
}
else
{
String x=str.substring(pos2,str.length());
result.add(x);
}
}
for(int i=0;i<result.size();i++)
System.out.println(result.get(i));
}
}
这是我写的类 输出结果是:
龙牌石膏板
水泥压力板
石膏板
压力板
public static void main(String[] args) {
String str = "龙牌石膏板(1.2*3)水泥压力板(1.2*2.4)石膏板(1.2*3)压力板(1.2*2.4)";
String[] strs = str.split("\\(.*?\\)");
for(String s : strs) {
System.out.println(s);
}
}
}