Deprecated: Typecho\Widget\Request::getServer(): Implicitly marking parameter $default as nullable is deprecated, the explicit nullable type must be used instead in D:\PHP_HOME\www\gp_blog\var\Typecho\Widget\Request.php on line 219

Deprecated: Typecho\Request::getServer(): Implicitly marking parameter $default as nullable is deprecated, the explicit nullable type must be used instead in D:\PHP_HOME\www\gp_blog\var\Typecho\Request.php on line 349

Deprecated: Typecho\Widget\Response::goBack(): Implicitly marking parameter $suffix as nullable is deprecated, the explicit nullable type must be used instead in D:\PHP_HOME\www\gp_blog\var\Typecho\Widget\Response.php on line 158

Deprecated: Typecho\Widget\Response::goBack(): Implicitly marking parameter $default as nullable is deprecated, the explicit nullable type must be used instead in D:\PHP_HOME\www\gp_blog\var\Typecho\Widget\Response.php on line 158
JavaScript substring() 方法 - 开发者

定义和用法
substring() 方法用于提取字符串中介于两个指定下标之间的字符。

substring() 方法返回的子串包括 开始 处的字符,但不包括 结束 处的字符。

语法

string.substring(from, to)

from: 必需。一个非负的整数,规定要提取的子串的第一个字符在 string Object 中的位置。
to: 可选。一个非负的整数,比要提取的子串的最后一个字符在 string Object 中的位置多 1。
如果省略该参数,那么返回的子串会一直到字符串的结尾。

实例
在本例中,我们将使用 substring() 从字符串中提取一些字符:

<script>
var str="Hello world!";
document.write(str.substring(3)+"<br>");
document.write(str.substring(3,7));
</script>

以上代码输出结果:

lo world!
lo w


标签: none

评论已关闭