user1448108
user1448108

Reputation: 477

How to find a particular string in a paragraph in android?

In my project the data is stored in html format along with image tag. For example the following data is stored in html format and it contains 2 to 3 images.

Mother Teresa as she is commonly known, was born Agnes Gonxha Bojaxhiu. Although born on the 26 August 1910, she considered 27 August, the day she was baptized, to be her "true birthday". “By blood, I am Albanian. By citizenship, an Indian. By faith, I am a Catholic nun. As to my calling, I belong to the world. As to my heart, I belong entirely to the Heart of Jesus." img ----- src="image1.png" ----> Mother Teresa founded the Missionaries of Charity, a Roman Catholic religious congregation, which in 2012 consisted of over 4,500 sisters and is active in 133 countries.img ----- src="image2.png" ---->. She was the recipient of numerous honours including the 1979 Nobel Peace Prize. She refused the conventional ceremonial banquet given to laureates, and asked that the $192,000 funds be given to the poor in India. img ----- src="image3.png" ---->

Now from the above data I need to find how many images the paragraph has and need to get all the image names along with the extensions and should display them in android. Tried with splitting but did not work. Please help me regarding this.

Thanks in advance

Upvotes: 1

Views: 1580

Answers (3)

Kumar Vivek Mitra
Kumar Vivek Mitra

Reputation: 33534

Try this,

Use BreakIterator Class

eg :

BreakIterator boundary = BreakIterator.getSentenceInstance();

      boundary.setText(Your_entire_string);

      int start = boundary.first();

      int end = boundary.next();

Then with the help of looping you can iterate through all the lines.

Upvotes: 0

Ponmalar
Ponmalar

Reputation: 7031

Check below for number of occurrences

  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

Upvotes: 0

ankita gahoi
ankita gahoi

Reputation: 1562

you can use contains method of String class

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

}

it will return true or false.

Upvotes: 1

Related Questions