javascript
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 errordocument.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
總結
以上是生活随笔為你收集整理的JavaScript中的String substring()方法和示例的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 牙缝大矫正多少钱啊?
- 下一篇: 系统固件升级_固件和操作系统之间的差异
