开发者

How do i select a substring from a string acording to the last "/"?

开发者 https://www.devze.com 2023-03-20 07:00 出处:网络
I have a image url and would like to subtract the last string after \"/\" , for example from string \"www.abc.com/images/photo.jpg\" i would like t开发者_运维知识库o get the string \"photo.jpg\". How

I have a image url and would like to subtract the last string after "/" , for example from string "www.abc.com/images/photo.jpg" i would like t开发者_运维知识库o get the string "photo.jpg". How can i do this ?


Use NSString -(NSString *)lastPathComponent; for that.


    String s = "www.abc.com/images/photo.jpg";


        String[] newS = s.split("/");

        String correctS = newS[newS.length-1];

correctS will hold your answer


Here's a regex for it:

(?!/)[^/]*$

0

精彩评论

暂无评论...
验证码 换一张
取 消