ant2009
ant2009

Reputation: 22708

Using substring to extract part of a string

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.

Upvotes: 0

Views: 851

Answers (1)

Orr Benyamini
Orr Benyamini

Reputation: 405

You could use

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

Upvotes: 4

Related Questions