JavaScript中字符操作之大小写转换
2024-09-04 12:56:16
1、toUpperCase() 方法用于把字符串转换为大写
var str = prompt("请输入需转换大写的字符串:");
str = str.toUpperCase();
console.log(str);
toUpperCase 方法
- 返回一个字符串,该字符串中的所有字母都被转化为大写字母。
- 对非字母字符不会产生影响。
2、toLowerCase() 方法用于把字符串转换为大写
var str = prompt("请输入需转换大写的字符串:"); str = str.toLowerCase(); console.log(str);
toLowerCase 方法
- 返回一个字符串,该字符串中的字母被转换为小写字母。
- 对非字母字符不会产生影响。
3、番外篇
运用操作字符concat(连接字符串),slice(截取字符串)、以及charAt(给索引查字符)和indexOf(给字符查索引)实现输入英文首字母大写。
var strs = prompt("请在下方输入英文句子:"); //将输入内容赋值给strs var First = strs.charAt(0).toUpperCase();//给索引为0的字符大写 s = strs.indexOf("."); //从这段话开头开始,查找字符为英文。的第一个索引 cvs =strs.slice(1,s).toLowerCase(); //截取这段话剩余单词全部转小写
console.log(First.concat(cvs)); //连接字符串并于控制台打印
最新文章
- Reporting Services 错误案例一则
- Codeforces Round #371 (Div. 1)
- runtime学习实战一:类的属性进行归档解档
- AndroidManifest.xml的android:name是否带.的区别
- 对于大一学习计算机的新手(c/c++ )提出一些学习经验
- .Net性能优化时应该关注的数据
- BootStrap2学习日记3--响应式布局实用类
- SQLite 入门教程(一)基本控制台(终端)命令 (转)
- webkit中DOM 事件有多少
- spark二次排序
- (转)在Eclipse中使用JUnit4进行单元测试
- Spring IOC之Bean 概述
- js 获取n天前的时间
- MyBatis 的小细节问题
- 解决 Cannot find OpenSSL&#39;s <;evp.h>; 和sasl.h not found!
- 设置Mac 终端走代理
- zabbix监控特定脚本有无生成
- Servlet交互与JSP
- 在Visual Stdio 2012中编译执行JM18.6的方法
- Java设计模式应用——工厂模式
热门文章
- java中Logger.getLogger(Test.class),即log4日志的使用
- SQL使用union合并查询结果(转载)
- 170324、Spring 处理器和Resource
- java nio探险
- CodeForces 732C Sanatorium
- python AI(numpy,matplotlib)
- Python进阶知识
- Python3: Command not found(Mac OS)
- leetcode_Basic Calculator
- 14.Iterate a Cursor in the mongo Shell-官方文档摘录