Extract base url from full url

前端 未结 3 1960
小鲜肉
小鲜肉 2021-02-08 10:42

Any quick way to extract base url from full url? for e.g., if i have http://test.example.com/abcd/test.html - i want only http://test.example.com.

I can always do strin

3条回答
  •  醉话见心
    2021-02-08 11:22

    There's nothing in the Android URI class that gives you the base URL directly- As gnuf suggests, you'd have to construct it as the protocol + getHost().

    The string parsing way might be easier and let you avoid stuffing everything in a try/catch block. Just take a substring of the URL, everything from the beginning of the string to the third "/" symbol.

提交回复
热议问题