从字符串中删除 URL 前缀(http:/、www 等)[已关闭]

2022-09-01 11:07:25

我需要从我的字符串中删除各种“网络开头”

我的 TextView 必须没有“http://”、“http:// www.”、“www.”和其他 URL 前缀。

请你能帮我这个吗?


答案 1

使用 的实例并使用它来根据需要进行拆分:URI

URI uri = new URI(whateverYourAddressStringIs);
String path = uri.getPath(); // split whatever you need

http://developer.android.com/reference/android/net/Uri.html


答案 2

您可以使用正则表达式来执行此操作

"www.aaa".replaceFirst("^(http[s]?://www\\.|http[s]?://|www\\.)","")