1

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

brianestey
  • 8,202
  • 5
  • 33
  • 48
user1448108
  • 467
  • 2
  • 10
  • 28
  • 1
    Take a look at [this question](http://stackoverflow.com/q/1732348/335858). – Sergey Kalinichenko Jun 11 '12 at 03:51
  • 1
    I think you could do something with regular expressions. See this [page](http://docs.oracle.com/javase/tutorial/essential/regex/) for tutorials. – brianestey Jun 11 '12 at 03:52
  • What did you try and how did it "not work"? Splitting **is** the way to go... or you can just search for " – jahroy Jun 11 '12 at 04:04
  • I have to agree with brianestey: this is what regex is for. With it you not only find the img tag, but extract the image names as you go. – cstrutton Jun 11 '12 at 04:06

3 Answers3

1

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.

ankita gahoi
  • 1,532
  • 2
  • 15
  • 28
0

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

Ponmalar
  • 6,871
  • 10
  • 50
  • 80
0

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.

Kumar Vivek Mitra
  • 33,294
  • 6
  • 48
  • 75