js的字符串charAt()方法
//字符中的字符从左向右进行索引,由0开始,字符串中的空格也算在内
var string = "charAt find word position";
document.write("charAt find word position"+ "<br/>")
document.write("string.charAt(0) is:" + string.charAt(0) + "<br/>");
document.write("string.charAt(1) is:" + string.charAt(1) + "<br/>");
document.write("string.charAt(2) is:" + string.charAt(2) + "<br/>");
document.write("string.charAt(3) is: " + string.charAt(3) + "<br/>");
document.write("string.charAt(4) is: " + string.charAt(4) + "<br/>");
document.write("string.charAt(5) is: " + string.charAt(5) + "<br/>");
document.write("string.charAt(6) is: " + string.charAt(6) + "<br/>");
document.write("string.charAt(7) is: " + string.charAt(7) + "<br/>");
document.write("string.charAt(string.length-2) is: " + string.charAt(string.length-2) + "<br/>")
document.write("string.charAt(string.length-1) is: " + string.charAt(string.length-1) + "<br/>") //输出结果
string.charAt(0) is:c
string.charAt(1) is:h
string.charAt(2) is:a
string.charAt(3) is: r
string.charAt(4) is: A
string.charAt(5) is: t
string.charAt(6) is:
string.charAt(7) is: f
string.charAt(string.length-2) is: o
string.charAt(string.length-1) is: n
//返回该字符串
function findCharAt(str,n){
var obj = String(str); // 转化为字符串
var pos; //定义变量
pos = obj.charAt(n-1); //查找的索引
return pos; //返回字符
}
alert(findCharAt("这是第几个",1));
js的字符串charAt()方法的更多相关文章
- js中字符串的方法
js String对象中常用方法小结,需要的朋友可以参考下: 1.charCodeAt方法返回一个整数,代表指定位置字符的Unicode编码. strObj.charCodeAt(index) 说明: ...
- JS常用字符串处理方法应用总结
这篇文章主要总结了JS常用字符串的处理方法,需要的朋友可以参考下 1.indexOf()方法,从前往后查找字符串位置,大小写敏感,从0开始计数.同理,lastIndexOf() 方法从后往前,两个 ...
- [JS高程] 字符串模式匹配方法
目录 1. RegExp 对象 2. 字符串模式匹配方法 2.1 match() , search() 2.2 replace() 2.2.1 第二个参数为字符串的应用情况 2.2.2 第二个参数为函 ...
- js常用字符串处理方法
JS自带函数concat将两个或多个字符的文本组合起来,返回一个新的字符串.var a = "hello";var b = ",world";var c = a ...
- JS截取字符串 charAt(),slice(),substring(),substr()
1. charAt(i)输出指定下标的字母,长度为1,适用于把字符串切割成单个字符串. 2. slice() 和 substring() 都支持1-2个参数,第一个参数是开始位置,第二个参数是结束位置 ...
- js截取字符串的方法
1,slice(a, b) 第一个参数表示起始位置,第二个表示截取到但不包含 关于参数正负问题,只要记住一点:永远不能倒着截取!否则返回空字符串 2,substring(a, b) 第一个参数表示起始 ...
- js 把字符串当做方法执行
<SCRIPT LANGUAGE="JavaScript"> function test(str){ alert(str); } eval('test("aa ...
- JS对象 charAt() 方法可返回指定位置的字符。返回的字符是长度为 1 的字符串。
返回指定位置的字符 charAt() 方法可返回指定位置的字符.返回的字符是长度为 1 的字符串. 语法: stringObject.charAt(index) 参数说明: 注意:1.字符串中第一个字 ...
- 不要再混淆js的substring和substr了!(附js所有字符串方法)
一.字符串操作方法 js中字符串方法操作有很多:concat.indexOf.... 这里只要介绍两种经常混淆的字符串截取方法:substring.substr 二.从例子入手 let str = ' ...
随机推荐
- 6. GC 调优(工具篇) - GC參考手冊
进行GC性能调优时, 须要明白了解, 当前的GC行为对系统和用户有多大的影响. 有多种监控GC的工具和方法, 本章将逐一介绍经常使用的工具. 您应该已经阅读了前面的章节: 垃圾收集简单介绍 - GC參 ...
- R语言设置write.table()输出的文件格式
write.table(),是保存数据为文件的函数. > xiaohuqingdan <- c(3900088702, 3900072499,3900021029) > xiaohu ...
- 【好文收藏】javascript中event对象详解
event代表事件的状态,例如触发event对象的元素.鼠标的位置及状态.按下的键等等. event对象只在事件发生的过程中才有效. event的某些属性只对特定的事件有意义.比如,fromEleme ...
- 逻辑斯特回归(logistic regression)的迭代变权最小平方差算法(IRLS)
参考资料:http://blog.csdn.net/xuanyuansen/article/details/41050507 习题: 数据及代码: https://pan.baidu.com/s/1 ...
- AOP称为面向切面编程,在程序开发中主要用来解决一些系统层面上的问题
AOP称为面向切面编程,在程序开发中主要用来解决一些系统层面上的问题,比如日志,事务,权限等待,Struts2的拦截器设计就是基于AOP的思想,是个比较经典的例子. 一 AOP的基本概念 (1)Asp ...
- c# combobox 绑定报错
comboBoxPlanResult.DataSource =new BindingSource(o,null);comboBoxPlanResult.DisplayMember ="Key ...
- MySQl安装全解
这是第二次安装MySql了.第一次安装花了几个小时,理解安装的每一个页面,这次光寻找安装包就找了几个.因此感觉有必要做一次全面的安装笔记.(有点浪费时间了,可是感觉非常值得)本人系统是window7. ...
- php对gzip的使用(理论)
gzip是GNU zip的缩写,它是一个GNU自由软件的文件压缩程序,也经常用来表示gzip这种文件格式.软件的作者是Jean-loup Gailly和Mark Adler.1992年10月31日第一 ...
- POSIX是什么?
1.什么是POSIX? POSIX是可移植操作系统接口(Portable Operating System Interface for UNIX)的缩写,是IEEE为了在各种UNIX操作系统上运行软件 ...
- 帝国cms目录结构
/ 系统根目录├d/ 附件和数据存放目录 (data) │├file/ 附件存放目录 │├js/ JS调用生成目录 │└txt/ 内容存文本存放目录 ├ ...