龙牌石膏板(1.2*3)水泥压力板(1.2*2.4)石膏板(1.2*3)压力板(1.2*2.4)

解决方案 »

  1.   


    var str ="龙牌石膏板(1.2*3)水泥压力板(1.2*2.4)石膏板(1.2*3)压力板(1.2*2.4)"'
    str.substring(0,5);//依次截取 
      

  2.   

    使用正则表达式来匹配括号及括号中的内容,然后全部替换成一个特殊字符如:|,
    然后再Split。
      

  3.   

    运行下面的代码: String string="龙牌石膏板(1.2*3)水泥压力板(1.2*2.4)石膏板(1.2*3)压力板(1.2*2.4)";
     String reg = "[(\\w+\\.\\*)]";
     Pattern p = Pattern.compile(reg);
     Matcher m = p.matcher(string);
     String strTrim = m.replaceAll("");
     System.out.println("strTrim========"+strTrim);
    得到结果:龙牌石膏板水泥压力板石膏板压力板
      

  4.   


    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:龙牌石膏板水泥压力板石膏板压力板

    }

    }
      

  5.   

    package com.liantuo.hamburger.request.crs.regex;import org.apache.oro.text.regex.MalformedPatternException;
    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));
        }
    }结果是:
    龙牌石膏板
    水泥压力板
    石膏板
    压力板
    龙牌石膏板水泥压力板石膏板压力板
      

  6.   

    import java.util.ArrayList;public class Test {
    /**
     * @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));   
    }
    }
    这是我写的类  输出结果是:
    龙牌石膏板
    水泥压力板
    石膏板
    压力板
      

  7.   

    String[] strs = str.split("\\(.*?\\)");
      

  8.   

    晕倒,怎么贴上去的那么难看,重新贴一次。public class TestTest {
        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);
            }
        }
    }