zoukankan      html  css  js  c++  java
  • JavaScript-string

        var str2=String("AsD56.com.22.33")
        console.log(str2)
        console.log(str2.toLowerCase())  /*转换为小写字母*/
        console.log(str2.toUpperCase())/*转换为大写字母*/
        console.log(str2.indexOf("56")) /*查找某字符所在位置*/
        console.log(str2.substring(0,2)) /*截取字符串中介于两个指定下标之间的字符,参数为开始和结束索引,不能为负值*/
        console.log(str2.substr(4,4))  /*截取字符串中介于两个指定下标指定的字符*/
        console.log(str2.slice(-4,-2))/*截取字符串中介于两个指定下标之间的字符,参数为开始和结束索引,可以为负值*/
        console.log(str2.split(".",2)) /*第一个参数按照那个分隔符截取,第二个参数截取字符数,将截取的字符放到数组里面*/
        var str3=str2.split(".");
        console.log(str3.slice(-2,str3.length))   /*负值从后面往前截取*/
    

      

  • 相关阅读:
    Single Number II
    Best Time to Buy and Sell Stock
    Linked List Cycle
    Single Number
    Max Points on a Line
    Strategy
    LRU Cache
    Word Break II
    Text Justification
    Median of Two Sorted Arrays
  • 原文地址:https://www.cnblogs.com/bpdxqx/p/6027275.html
Copyright © 2011-2022 走看看