当前位置:网站首页>JS字符串对象基础操作方法
JS字符串对象基础操作方法
2022-08-09 15:02:00 【BigData_C】
字符串对象提供了一些用于截取字符串、连接字符串、替换字符串的属性和方法。

定义字符串:var a='abcasdfrgtohbjdurygvbo' 问题如下
1.字符串的长度
2.取出指定位置的字符,如:0、3、5等
3.查找指定字符是否在以上字符中存在,如:i、c等
4.替换指定字符,如:g替换为22,ss替换为b等操作方法
5.截取指定开始位置到结束位置的字符串,如:取得1-5的字符串
6.找出以上字符串中出现次数最多的字符串和出现的次数
1.
var a='abcasdfrgtohbjdurygvbo';
console.log(a.length);//2.
console.log(a.charAt('0'));
console.log(a.charAt('3'));
console.log(a.charAt('5')); //3.
console.log(a.indexOf("c") != -1);
console.log(a.indexOf("i") != -1);
console.log(a.indexOf("b") != -1); //4.
while (a.indexOf('g','s')!==-1){
a=a.replace('g','22');
a=a.replace('s','b');
}
console.log(a); //5.
console.log(a.substr(1,5)); //6.
var str='wegwvwsfsfgwvawrgsdvwa';
var o={};
for(var i=0;i<a.length;i++){
var chars=a.charAt(i);
if(o[chars]){
o[chars]++
}else{
o[chars]=1;
}
}
console.log(o);
var max=0;
var sxm='';
for(var k in o){
if(o[k]>max){
max=o[k];
sxm=k;
}
}
console.log('出现最多是'+sxm+'次数是'+max);边栏推荐
- Vim practical skills_3. Visual mode and command mode
- Candide3 face animation model
- GStreamer应用开发手册学习笔记之二
- wireshark抓包新手使用教程
- Unity Shader零基础入门4:纹理贴图与法线贴图
- FFmpeg源码剖析-通用:ffmpeg_parse_options()
- 聚集索引和非聚集索引
- C语言,输入一个10以内的随机数,按要求求得表达式的值。
- 【QT】QLayout: Attempting to add QLayout “to ***“, which already has a layout的终极解决方法
- Correlation analysis
猜你喜欢
随机推荐
灰色关联分析
FFmpeg源码剖析-通用:ffmpeg_parse_options()
7z解压软件(小巧好用)。百度云下载链接
【Postgraduate Work Weekly】(The third week)
List,Set,Map,Queue,Deque,Stack遍历方式总结
RTP协议封装音视频媒体数据详解
关于sql语句中union和or的区别
FileInputStream与BufferedInputStream的区别
String的构造方法,其他方法
【QT】窗口几何布局学习
堆(heap)系列_0x07:NT堆调试支持_滞后发现调试支持
面试经历(华为,瑞晟,大华,海康,虹软,顺丰)
堆(heap)系列_0x0A:3种方法一次性解决堆溢出问题
Fiddler抓包夜神模拟器
Face recognition sample code analysis (2) - face recognition analysis
GCC编译过程
CTF online encryption and decryption and common tools
CTF在线加解密以及常用工具
unity shader 入门 全透明与半透明效果实现
模糊综合评价









