美文网首页
字符串笔记

字符串笔记

作者: UmustHU | 来源:发表于2018-08-16 18:17 被阅读0次
indexOf

从字符串中查找指定字符串,如果能够在字符串中查找到结果,则返回指定字符串所在位置,如果找不到,返回-1

let str = 'welcome to my notepad';
console.log(str.indexOf('to'));
//返回结果
8

let str = 'welcome to my notepad';
console.log(str.indexOf('hello'));
//返回结果
-1
include

从字符串中查找指定字符串,如果有结果返回true,没有结果返回false

let str = 'welcome to my notepad';
console.log(str.includes('to'));
//返回结果
true
//判断浏览器
console.log(navigator.userAgent.includes('Chrome'))
startsWith

判断某字符串是否是以指定字符串开头

let str = 'http://www.baidu.com/';
console.log(str.startsWith('http'));
//返回结果
true
endsWith

判断某字符串是否是以指定字符串结尾

let str = 'http://www.baidu.com/img/bd_logo1.png';
console.log(str.endsWith('.png'));
//返回结果
true

相关文章

  • Python ☞ day 3

    Python学习笔记之 字符串 & 列表 & 元组 & 字典 字符串 什么是字符串? 字符串运算 字符串方法 列表...

  • 求字符串长度(c语言笔记)

    求字符串长度(c语言笔记) -------------------------------------------...

  • 【Python基础】3.字符串

    本篇笔记知识点:-修改字符串字符串:修改大小写,拼接增加/删除空白下标&切片其他字符串常用操作 字符串 字符串:一...

  • 《Python之字符串》

    今天才把字符串的笔记更新上去。有需要具体原脚本笔记的脚本可以联系我。 # python中的字符串 通常使用""或者...

  • FreeCodeCamp Basic Algorithm Scr

    FreeCodeCamp 初级算法 个人笔记,仅作留档 Reverse a String 翻转字符串先把字符串转化...

  • 2019-03-28

    A Byte of Python 笔记 字符串 一个字符串(string)就是字符(characters)的序列(...

  • 2018-07-17

    sql笔记1 sql笔记2 case when then 比较字符串 left join 最近使用left joi...

  • OC的一些基本声明方法整理

    (本文参考资料整理,仅作为初学笔记) 一,字符串 1.字符串字面量 NSString *a=@"this is a...

  • python学习笔记18_字符串相关操作

    python 笔记18 1.字符串简单操作 1.1 重复输出字符串 1.2 通过索引获取字符串字符 通过索引获取字...

  • python学习笔记(三)字符串

    个人笔记,仅供参考 三、使用字符串 1、字符串基本操作 所有的标准序列操作都适用于字符串,但是字符串不可变,所以不...

网友评论

      本文标题:字符串笔记

      本文链接:https://www.haomeiwen.com/subject/nwbobftx.html