本文共 613 字,大约阅读时间需要 2 分钟。
substring()
returns a portion of a string and it’s similar to , with some key differences.
substring()
返回字符串的一部分,它类似于 ,但有一些关键区别。
If any parameter is negative, it is converted to 0
. If any parameter is higher than the string length, it is converted to the length of the string.
如果任何参数为负,则将其转换为0
。 如果任何参数大于字符串长度,则将其转换为字符串的长度。
So:
所以:
'This is my car'.substring(5) //'is my car''This is my car'.substring(5, 10) //'is my''This is my car'.substring(5, 200) //'is my car''This is my car'.substring(-6) //'This is my car''This is my car'.substring(-6, 2) //'Th''This is my car'.substring(-6, 200) //'This is my car'
翻译自:
转载地址:http://jlqgb.baihongyu.com/