Please tell me how you can from this abracadabra:

<img src="https://pp.vk.me/c618831/v618831071/1c22e/_v5QVn3WAVk.jpg" class="ph_img" data-id="-52952419_345698085" data-src_big="https://pp.vk.me/c618831/v618831071/1c22f/JRueLkVn0SY.jpg|604|604"> 

get this link:

 https://pp.vk.me/c618831/v618831071/1c22f/JRueLkVn0SY.jpg 

I wanted to use the replace ('"', ' '); method, and then use the split() method and create an array and at the end just take the array element I need.

The problem is that I can not compile abracadabra because of the ubiquitous quotes.

What can be done?

    1 answer 1

    The most primitive method is based on the substring(...) and indexOf(...) methods of the String class:

     String s = "<img src=\"https://pp.vk.me/c618831/v618831071/1c22e/_v5QVn3WAVk.jpg\" class=\"ph_img\" data-id=\"-52952419_345698085\" data-src_big=\"https://pp.vk.me/c618831/v618831071/1c22f/JRueLkVn0SY.jpg|604|604\">"; String link = s.substring(s.indexOf("data-src_big=\"")+14, s.indexOf("|")); 

    The problem is that I can not compile abracadabra because of the ubiquitous quotes

    The quotes need to be escaped by backslashes:

     \" 

    UPD . With jsoup your problem can be solved, for example, like this:

     Document page = Jsoup.parse("<img src=\"https://pp.vk.me/c618831/v618831071/1c22e/_v5QVn3WAVk.jpg\" class=\"ph_img\" data-id=\"-52952419_345698085\" data-src_big=\"https://pp.vk.me/c618831/v618831071/1c22f/JRueLkVn0SY.jpg|604|604\">"); String link = page.select("img").get(0).attr("data-src_big").split(Pattern.quote("|"))[0]; 
    • Thanks for the answer. I got Abracadabra by parsing the page. I will not be able to manually place the slashes. Is it possible to somehow make it programmatically. - Kojer Defor 2:44
    • one
      @KojerDefor, Special characters need to be escaped just in case they are recorded manually, in other cases screening is not necessary. And also, if you parse HTML with the help of something like jsoup , then you can get the required link more easily. - post_zeew 2:51
    • Yes, you can probably. I will continue to deal with jsoup . Thank. - Kojer Defor