JavaScript中的String substring()方法和示例

JavaScript | 字符串substring()方法 (JavaScript | String substring() Method)

The String.substring() method in JavaScript is used to return a part of the string. The substring() extracted is from the given start and end index of the string.

JavaScript中的String.substring()方法用于返回字符串的一部分。 提取的substring()来自给定的字符串开始结束索引。

Syntax:

句法:

    string.substring(startIndex, endIndex);

Parameter(s):

参数:

The method accepts two parameters, they are the starting and ending index of the substring string which is to be extracted.

该方法接受两个参数,它们是要提取的子字符串字符串的开始和结束索引。

Return value:

返回值:

The return type of this method is string which is the substring output of the given string.

此方法的返回类型是string ,它是给定字符串的子字符串输出。

Browser support: Chrome, Internet explorer, Mozilla, Safari, Opera mini.

浏览器支持: Chrome,Internet Explorer,Mozilla,Safari,Opera mini。

Example 1:

范例1:

<script>
document.write("Hello".substring(1,3) + "<br/>");
document.write("Hello".substring(0,2) + "<br/>");
document.write("Hello".substring(0,5) + "<br/>");
document.write("Hello".substring(0,8) + "<br/>"); //no error
document.write("Hello World!".substring(6,12) + "<br/>");
</script>

Output

输出量

el
He
Hello
Hello
World!

Example 2:

范例2:

<script>
str = "www.includehelp.com";
document.write(str.substring(0,3) + "<br/>");
document.write(str.substring(4,15) + "<br/>");
document.write(str.substring(16,19) + "<br/>");
document.write(str.substring(0) + "<br/>");
document.write(str.substring(4) + "<br/>");
document.write(str.substring(16) + "<br/>");
</script>

Output

输出量

www
includehelp
com
www.includehelp.com
includehelp.com
com

翻译自: https://www.includehelp.com/code-snippets/string-substring-method-with-example-in-javascript.aspx

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/380077.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Java——方法(练习九九乘法表)

public static void(int,byte…) xxx(int a,int b) 修饰符 返回值类型 方法名(参数类型 参数名1&#xff0c;参数类型 参数名2…)&#xff5b; 方法体语句&#xff1b; return 返回值&#xff1b; &#xff5d; public class fangfa {public static void main(String[] ar…

UVA 10405-Longest Common Subsequence

最长公共子序列&#xff0c;值得注意的是这道题不能用scanf读字符串。 #include<stdio.h>#include<string.h>#define MAXD 1005char s1[MAXD], s2[MAXD];int dp[MAXD][MAXD];int max( int a, int b){return a > b ? a : b;}void solve(){int len1 strlen(s1 …

对初学者的几点建议

http://www.cnblogs.com/thcjp/archive/2007/06/14/783157.html 天轰穿vs2005入门.net2.0系列视频教程推出已经有接近8个月了&#xff0c;这期间我收到非常多的反馈&#xff0c;我只能用非常来形容&#xff0c;呵呵&#xff0c;当然也了解了很多人的心理和学习方法。但是很遗憾…

系统固件升级_固件和操作系统之间的差异

系统固件升级固件 (Firmware) Firmware is somewhere similar to software but it is not a software. Somehow it is a modified form of software. 固件与软件相似&#xff0c;但不是软件。 不知何故&#xff0c;它是软件的修改形式。 Firmware is fixed data or code that …

cobalt strick 4.0 系列教程 (5)--- 获取立足点

https://blog.ateam.qianxin.com/CobaltStrike4.0%E7%94%A8%E6%88%B7%E6%89%8B%E5%86%8C_%E4%B8%AD%E6%96%87%E7%BF%BB%E8%AF%91.pdf 0x01 客户端 System Profiler [即探针] System Profiler 是一个为客户端攻击提供的侦察工具。这个工具启动一个本地的 web 服务器&#xff0…

[转]sql,N/$/#/@的含义和作用

declare sql nvarchar(4000)set sql Nselect TotalRecordscount(*) from N( sqlFullPopulate N) a EXEC sp_executesql sql,NTotalRecords int output, TotalRecords output 问题&#xff1a;sql 后面有个N, N 起什么作用? 答案&#xff1a; 加上 N 代表存入数据库时…

Java——方法重载(overload)(比较两个数据是否相等)

重载&#xff1a;方法名相同&#xff0c;参数列表不同&#xff0c;与返回值类型无关 重载的分类&#xff1a; 1&#xff0c;参数个数不同 ①&#xff0c;④&#xff0c;⑤&#xff0c;⑥&#xff1b; 2&#xff0c;参数类型不同 ①&#xff0c;②&#xff0c;③、 ⑤&#x…

scala怎么做幂运算_Scala幂(幂)函数示例

scala怎么做幂运算Scala programming language has a huge set of libraries to support different functionalities. Scala编程语言具有大量的库来支持不同的功能。 scala.math.pow() (scala.math.pow()) The pow() function is used for the exponential mathematical opera…

frame--转载

所谓框架便是网页画面分成几个框窗&#xff0c;同时取得多个 URL。只 要 <FRAMESET> <FRAME> 即可&#xff0c;而所有框架标记 要放在一个总起的 html 档&#xff0c;这个档案只记录了该框架 如何划分&#xff0c;不会显示任何资料&#xff0c;所以不必放入 <…

cobalt strick 4.0 系列教程(6)Payload Artifact 和反病毒规避

0x01 哲学 Strategic Cyber 责任有限公司会定期回答有关规避的问题。Cobalt Strike 是否能够绕过 AV 产品&#xff1f;它能绕过哪些 AV 产品&#xff1f;它多久检查一次&#xff1f; Cobalt Strike 默认的 Artifact 可能会被大多数终端安全解决方案拦截。规避不是 Cobalt Str…

【转】企业开发的困境与变局

原文&#xff1a;企业开发的困境与变局 文 / 刘江 算起来&#xff0c;《程序员》已经有几年时间没有大篇幅讨论企业软件开发这个话题了。这其实挺奇怪的。要知道&#xff0c;按类别来分&#xff0c;国内从事企业软件开发的技术人员是最多的&#xff0c;从CSDN和《程序员》联合举…

c# 类对象和实例对象_C#类和对象能力问题 套装4

c# 类对象和实例对象1) What are the correct statements about given code snippets? using System;public class Example{virtual private int X;private int Y;static void Main(string[] args){Console.WriteLine("Hello World");}}Hello WorldHelloWorldSyntax…

linkBar组件学习--设置linkBar子项的竖直间距.

效果&#xff1a;代码&#xff1a; <?xml version"1.0" encoding"utf-8"?><!--http://blog.flexexamples.com/2008/04/20/setting-the-vertical-spacing-between-items-in-a-linkbar-control-in-flex/ --><mx:Application xmlns:mx"…

AES算法

算法简介 AES本质是一种对称分组密码体制&#xff0c;采用代替/置换网络。每轮由三层组成&#xff1a;线性混合层确保多轮之上的高度扩散&#xff0c;非线性层由16个S盒并置起到混淆的作用&#xff0c;秘钥加密层将子秘钥异或到中间状态。 AES加密数据块和秘钥长度可以是128比…

C——结构体

例题1&#xff1a;(使用结构体) 输入两个学生的学号、姓名和成绩&#xff0c;输出成绩较高的学生的学号、姓名和成绩 解题思路&#xff1a; (1)定义连个结构相同的结构体变量student1,student2; (2)分别输入两个学生的学号、姓名、和成绩&#xff1b; (3)比较两个学生的成…

web.config配置文件详解

<?xml version"1.0"?> <!--注意: 除了手动编辑此文件以外&#xff0c;您还可以使用 Web 管理工具来配置应用程序的设置。可以使用 Visual Studio 中的“网站”->“Asp.Net 配置”选项。 设置和注释的完整列表在 machine.config.comments 中&#xff0c…

离散数学群论_离散数学中的群论及其类型

离散数学群论半群 (Semigroup) An algebraic structure (G, *) is said to be a semigroup. If the binary operation * is associated in G i.e. if (a*b) *c a *(b*c) a,b,c e G. For example, the set of N of all natural number is semigroup with respect to the operat…

IDA使用方法-----1

0x01 启动IDA new&#xff1a;反汇编一个新文件go&#xff1a;运行&#xff0c;直接进入IDAPrevious&#xff1a;载入一个我们以前编译过的程序 如果不想每次都看到这个对话框&#xff0c;可以取消该对话框底部的Display at startup&#xff08;启动时显示&#xff09;&#x…

邮箱验证JS代码

方法一,用JSfunction finish_onclick() { var username document.getElementById("username");var pwhidden document.getElementById("pwhidden");if(username.value"") { alert("请填写您的企业邮箱地址&#xff01;");username.f…

objdump命令详解

objdump命令是用查看目标文件或者可执行的目标文件的构成的gcc工具。 选项 --archive-headers -a 显示档案库的成员信息,类似ls -l将lib*.a的信息列出。 -b bfdname --targetbfdname 指定目标码格式。这不是必须的&#xff0c;objdump能自动识别许多格式&#xff0c;比如…