Home > Net >  Using substring to extract part of a string
Using substring to extract part of a string

Time:02-13

I have the following string: https://dummycloud/image/fetch/f_webp,q_auto:best,w_1080,c_limit/auto/https://dummy.com/media/products/8/8/763160.jpg

And I am only interested in the this part that comes at the end: https://dummy.com/media/products/8/8/763160.jpg

I am using the following with StringBuilder

val url = imageUrl.substringAfterLast("https")

return StringBuilder()
    .append("https")
    .append(url)
    .toString()

Just wondering if there is a substringAfterLast that would keep the prefix https. As I have to use StringBuilder manually to append it from the extract string.

CodePudding user response:

You could use

imageUrl.substring(imageUrl.lastIndexOf(“https”));
  • Related