想要在某个单词之后分割字符串吗? [英] want to split a string after a certain word?

查看:31
本文介绍了想要在某个单词之后分割字符串吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:

var url="https://muijal-ip-dev-ed.my.salesforce.com/apexpages/setup/viewApexPage.apexp?id=066415642TPaE";

在此字符串中,我只需要

In this string i need only

url="https://muijal-ip-dev-ed.my.salesforce.com/"

我需要字符串,直到"com/"为止,其余字符串应删除.

i need string upto "com/" rest of the string should be removed.

推荐答案

在现代浏览器中,您可以使用 URL()

In modern browsers you can use URL()

var url=new URL("https://muijal-ip-dev-ed.my.salesforce.com/apexpages/setup/viewApexPage.apexp?id=066415642TPaE");

console.log(url.origin)

对于不受支持的浏览器,使用正则表达式

For unsupported browsers use regex

这篇关于想要在某个单词之后分割字符串吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆