[英]How can i trim a url in react native
How can I trim the below URL using javascript in react native?如何使用 javascript 在本机反应中修剪下面的 URL? this is the URL这是 URL
" https://economictimes.indiatimes.com/industry/banking/finance/banking/is-indias-current-banking-crisis-just-old-wine-in-a-new-bottle/articleshow/71451268.cms " “ https://economictimes.indiatimes.com/industry/banking/finance/banking/is-indias-current-banking-crisis-just-old-wine-in-a-new-bottle/articleshow/71451268.cms ”
I need to trim this to economictimes.indiatimes.com
.我需要将其修剪为economictimes.indiatimes.com
。
You can do something like this你可以做这样的事情
const url = "https://economictimes.indiatimes.com/industry/banking/finance/banking/is-indias-current-banking-crisis-just-old-wine-in-a-new-bottle/articleshow/71451268.cms";
const result = new URL(url).host;
console.log(result); // prints "economictimes.indiatimes.com"
You can see more about the URL
interface here您可以在此处查看有关URL
接口的更多信息
try this.尝试这个。
url = "https://economictimes.indiatimes.com/industry/banking/finance/banking/is-indias-current-banking-crisis-just-old-wine-in-a-new-bottle/articleshow/71451268.cms" var arr = url.split("/"); console.log(arr[2]);
url = "https://economictimes.indiatimes.com/industry/banking/finance/banking/is-indias-current-banking-crisis-just-old-wine-in-a-new-bottle/articleshow/71451268.cms" console.log(url.split("//")[1].split('/')[0]);
Try this!尝试这个!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.