標籤:
Js中字元截取常用的三個函數:slice()、substring()、substr()。
slice():
slice(start,[end])
第一個參數代表開始位置,第二個參數代表結束位置的下一個位置。
substring():
substring(start,[end])
第一個參數代表開始位置,第二個參數代表結束位置的下一個位置。
substr():
substr(start,[length])
第一個參數代表開始位置,第二個參數代表截取的長度。
註:字串都從0開始計起
Name: Ataw.Dev.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
TrueName: Ataw.Dev.Core
VersionName: 1.0.0.0
if (config.Name) { this.TrueName = config.Name; this.VersionsName = config.Name; if (config.Name.length == 0) { this.NameIsNull = true; } else { this.TrueName = this.TrueName.substring(0, this.TrueName.lastIndexOf(‘,‘)); this.TrueName = this.TrueName.substring(0, this.TrueName.lastIndexOf(‘,‘)); this.TrueName = this.TrueName.substring(0, this.TrueName.lastIndexOf(‘,‘)); this.VersionsName = this.VersionsName.substring(0, this.VersionsName.lastIndexOf(‘,‘)); this.VersionsName = this.VersionsName.substring(0, this.VersionsName.lastIndexOf(‘,‘)); this.VersionsName = this.VersionsName.substr(this.VersionsName.indexOf(‘,‘) + 1, 100); this.VersionsName = this.VersionsName.substr(9); }} else { this.NameIsNull = true;}
【JS Note】字串截取