Android RegEx第一点

时间:2012-12-12 08:26:46

标签: android regex

我希望获得图像和substr的描述第一点如何在android中执行此操作?

示例我有一些文字

  

文本这是text,texxt。 teeext wrwerwr bla bla

嗨给我一个

  

文本,这是文本,texxt。

怎么做?

2 个答案:

答案 0 :(得分:1)

假设您知道描述中只有一点:

public static void main(String[] args) {
        // TODO Auto-generated method stub
        String str = "Text this is text, texxt. teeext wrwerwr bla bla";
        String newstr="";

        if(null!=str && str.length() > 0 ){
             int endIndex = str.lastIndexOf(".");
            if(endIndex != -1)  {
                newstr = str.substring(0, endIndex); // not forgot to put check if( endIndex != -1)
        }
        }
        System.out.println(newstr);
    }

如果有多个要点:

public static void main(String[] args) {
        // TODO Auto-generated method stub
        String str = "Text this is text, texxt. teeext wrwerwr bla bla";
        if(null!=str && str.length() > 0 ){
             String [] strings = str.split("\\.");
        System.out.println(strings[0]);
        }
    }

答案 1 :(得分:0)

您不需要正则表达式,只需看一下:String.subSequence