JavaScript字符串对象substr方法入门实例(用于截取字符串)
作者:junjie 时间:2024-06-05 09:53:44
JavaScript substr 方法
substr 方法用于根据开始位置和长度截取字符串并返回截取部分字符串。其语法如下:
str_object.substr(start, length)
参数说明:
参数 | 说明 |
---|---|
str_object | 要操作的字符串(对象) |
start | 必需。开始截取的位置,从 0 开始计算;如果为负数则从字符串末尾开始计算(经测试,某些浏览器版本下无效) |
length | 可选。指要截取的字符串长度,省略则至到字符串结束 |
提示:substr 方法不符合 ECMAscript 标准,因此不建议使用。
substr 方法实例
<script language="JavaScript">
var str = "www.aspxhome.com";
document.write( str.substr(4,5) );
</script>
运行该例子,输出:asphome
asphome
标签:JavaScript,substr
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
使用Python爬取小姐姐图片(beautifulsoup法)
2022-05-02 04:01:44
![](https://img.aspxhome.com/file/2023/4/133694_0s.png)
Python实现word2Vec model过程解析
2023-10-07 14:22:10
![](https://img.aspxhome.com/file/2023/4/63254_0s.jpg)
MySQL使用聚合函数进行单表查询
2024-01-14 10:41:20
![](https://img.aspxhome.com/file/2023/5/68665_0s.png)
oracle逻辑运算符与其优先级简介
2023-07-15 00:28:26
python matplotlib饼状图参数及用法解析
2021-08-25 16:02:52
![](https://img.aspxhome.com/file/2023/8/97298_0s.png)
Python的进程,线程和协程实例详解
2021-05-05 04:35:59
![](https://img.aspxhome.com/file/2023/9/95559_0s.png)
MySQL如何利用DCL管理用户和控制权限
2024-01-14 13:33:21
微信小程序实现登陆注册滑块验证
2023-08-24 17:36:26
![](https://img.aspxhome.com/file/2023/7/56127_0s.jpg)
让设计散发文化韵味
2009-03-22 15:01:00
![](https://img.aspxhome.com/file/UploadPic/20093/22/e69687e58c96e6a8a1e59e8b-85s.jpg)
Python udp网络程序实现发送、接收数据功能示例
2023-12-03 11:12:52
![](https://img.aspxhome.com/file/2023/9/108109_0s.png)
python使用KNN算法识别手写数字
2022-02-20 10:48:23
MySQL server has gone away 问题的解决方法
2024-01-18 11:46:11
Python日志:自定义输出字段 json格式输出方式
2022-08-20 01:27:19
![](https://img.aspxhome.com/file/2023/7/93857_0s.jpg)
python读写文件操作示例程序
2021-04-03 13:09:49
使用Python进行中文繁简转换的实现代码
2021-05-04 09:19:03
python如何实现不可变字典inmutabledict
2023-11-20 11:09:46
深入浅析php json 格式控制
2024-05-11 09:51:53
多按钮共存——don’t make me think
2010-01-11 20:20:00
![](https://img.aspxhome.com/file/UploadPic/20101/11/btn_ryan_021-54s.jpg)
SQL Server误区30日谈 第9天 数据库文件收缩不会影响性能
2024-01-17 17:45:01
如何在Python中导入EXCEL数据
2022-08-01 01:51:01
![](https://img.aspxhome.com/file/2023/6/112826_0s.jpg)