js中substring截取字符串
时间: 2024-03-02 15:29:23 浏览: 69
javascript截取字符串(通过substring实现并支持中英文混合)
5星 · 资源好评率100%
在JavaScript中,可以使用substring()方法来截取字符串。该方法有两个参数,分别表示截取的起始位置和结束位置(不包括结束位置的字符)。如果省略第二个参数,则截取到字符串的末尾。例如:
var s = "http://c.biancheng.net/index.html";
var a = s.indexOf("c");
var b = s.indexOf("/", a);
var c = s.substring(a,b);
var d = s.slice(a,b);
通过上述代码,使用substring()方法可以截取到字符串中以第一个参数指定的字符为起点,到第二个参数指定的字符为终点(不包括终点字符)的子串。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [JS截取字符串(3种方法)](https://blog.csdn.net/lxw1844912514/article/details/123899878)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* [javascript截取字符串(通过substring实现并支持中英文混合)](https://download.csdn.net/download/weixin_38613154/13058467)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文