ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
## 字符串操作 * 获取字符串的长度 length ~~~ let serverType = "windows"; console.log(serverType.length); ~~~ * 检索字符,下标从0开始 ~~~ let serverType = "windows"; console.log(serverType[0]); ~~~ * 查找子字符串 ~~~ let serverType = "windows"; console.log(serverType.indexOf("dows"); ~~~ 如果子字符串存在,则会返回第一个字符在原字符串的位置索引;如果不存在则返回-1。 * 截取字符串 ~~~ let serverType = "windows"; console.log(serverType.slice(1,3)); ~~~ * 转换大小写 ~~~ let serverType = "Windows"; console.log(serverType.toLowerCase()); console.log(serverType.toUpperCase()); ~~~ * 替换字符串的某部分 ~~~ let serverType = "Windows"; console.log(serverType.replace("dows","dow")); ~~~ * 字符串转换成数字 ~~~ let myStr = "123"; let myNum = Number(myStr); typeof myNum; ~~~ * 数字转换成字符串 ~~~ let myNum = 123; let myStr = myNum.toString(); typeof myStr; ~~~