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.pswp.cn/news/380077.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/380077.shtml
英文地址,請注明出處:http://en.pswp.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;比如…