如何在android中的段落中找到特定的字符串?

时间:2012-06-11 03:46:43

标签: java android

在我的项目中,数据与图像标签一起以html格式存储。例如,以下数据以html格式存储,包含2到3个图像。

她是众所周知的特蕾莎修女,出生于Agnes Gonxha Bojaxhiu。虽然出生于1910年8月26日,但她认为8月27日,即她受洗的那一天,是她的“真正的生日”。 “靠血,我是阿尔巴尼亚人。通过公民身份,印度人。凭着信心,我是天主教修女。至于我的召唤,我属于这个世界。至于我的心,我完全属于耶稣的心。“ img ----- src =”image1.png“----> 母亲特蕾莎创立了慈善传教士,罗马天主教宗教团体,2012年由超过4,500名姐妹组成,活跃于133个国家。 img ----- src =“image2.png”----> 。她是获得多项荣誉,包括1979年诺贝尔和平奖。她拒绝向获奖者颁发传统的礼仪宴会,并要求向印度的穷人提供192,000美元的资金。 img ----- src =“image3.png”---->

现在从上面的数据我需要找到段落有多少图像,需要获取所有图像名称和扩展名,并在android中显示它们。试图分裂但没有奏效。请帮我解决这个问题。

提前致谢

3 个答案:

答案 0 :(得分:1)

你可以使用String类的contains方法

String a="hello";
String b="hello my name is this";
if(b.contains(a)){

}

它将返回true或false。

答案 1 :(得分:0)

检查下面的出现次数

  String searchFor = "is";
  String base = "This is the method";
  int len = searchFor.length();
  int result = 0;
  if (len > 0) 
  {  
     int start = base.indexOf(searchFor);
     while (start != -1) 
     {
        result++;
        start = base.indexOf(searchFor, start+len);
     }
  }
  System.out.println(result);

For More Det:http://www.roseindia.net/java/string-examples/java-string-occurrence-in-a-string.shtml

答案 2 :(得分:0)

试试这个,

使用BreakIterator Class

例如:

BreakIterator boundary = BreakIterator.getSentenceInstance();

      boundary.setText(Your_entire_string);

      int start = boundary.first();

      int end = boundary.next();

然后在循环的帮助下,您可以遍历所有行。