arduino的String类
来源:互联网 发布:别哭了宝贝网络歌手 编辑:程序博客网 时间:2024/06/05 16:54
String类主要的就是一些字符串处理函数,比string具有更多更轻大的功能,so用起来很爽!
下面是其主要函数介绍,用例主要参考官方资料。
1、定义,这个就不多说了
String stringOne = "Hello String"; String stringOne = String('a'); String stringTwo = String("This is a string"); String stringOne = String(stringTwo + " with more");String stringOne = String(13); String stringOne = String(analogRead(0), DEC); String stringOne = String(45, HEX); String stringOne = String(255, BIN); String stringOne = String(millis(), DEC);2、字符串的连接与追加,官方将两种功能分开了,其实觉得和在一起对比理解会更好一点
stringThree = stringOne + 123;stringThree = stringOne + 123456789;stringThree = stringOne + 'A';stringThree = stringOne + "abc";stringThree = stringOne + stringTwo;stringOne += 123456789;等同于stringTwo.concat(123456789);3、在字符串中中查找字符位置,返回值为给定字符的第一个位置,查找失败返回-1
indexOf('?'):从字符串头部开始查找
lastindexOf('?'):从尾部开始查找
int firstClosingBracket = stringOne.indexOf('>');默认是从头部开始查找,还可以指定开始位置int secondOpeningBracket = firstClosingBracket + 1;int secondClosingBracket = stringOne.indexOf('>', secondOpeningBracket );lastindexOf()的用法类似int lastParagraph = stringOne.lastIndexOf("<p");int secondLastGraf = stringOne.lastIndexOf("<p", lastParagraph - 1);4、length():字符串长度测量函数,返回值为字符串的长度
String txtMsg = "This is a test!";int lastStringLength = txtMsg.length();
5、trim():将字符串中的字符串去除,包括空格、回车、Tab等
String str = "this isa test ,do you kown?";stringOne.trim();6、大小写转换
大转小:toLowerCase()
小转大:toUpperCase()
7、替换:用后面的字符串替换前面的字符串
String stringOne = "<html><head><body>";stringTwo.replace("<", "</");8、查看字符串指定位置的字符:charAt(),返回值为给定位置的字符,如果超出范围会发生意想不到的错误。
改变字符串给定位置的字符:setcharAt,无返回值。
String reportString = "SensorReading: 456";char mostSignificantDigit = reportString.charAt(15);reportString.setCharAt(13, '=');9、判断字符串开头、结尾或者给定位置是否为给定字符串,是返回true,否则返回false
String stringOne = "HTTP/1.1 200 OK";if (stringOne.startsWith("HTTP/1.1")) { Serial.println("Server's using http version 1.1"); } if (stringOne.startsWith("200 OK", 9)) { Serial.println("Got an OK from the server"); }10、字符串的各种比较,包括==,!=,>,<,>=,<=。具体的函数有equals()、equalsIgnoreCase()(忽略大小写)、compareTo。字符串的比较式从前往后进行比较,以ASIIC码为标准。
11、字符串转换为整型:toInt(),返回值为转换后的整型值。
12、字符串解析函数:substring(?,...),返回值为指定位置的字符串值
String stringOne = "Content-Type: text/html";if (stringOne.substring(19) == "html") { Serial.println("It's an html file"); } if (stringOne.substring(14,18) == "text") { Serial.println("It's a text-based file"); }
0 0
- arduino的String类
- arduino的String类
- 基于Arduino实现Arduino控制的电灯
- 【Arduino】基于arduino的激光坦克
- 控制Arduino的利器-Windows Remote Arduino
- 控制Arduino的利器-Windows Remote Arduino
- arduino 各种类型转为String类型
- ubuntu调试arduino程序出现找不到<string>
- Arduino 的函数库
- Arduino串口的使用
- Arduino的数据类型
- Arduino的串口
- Arduino旅程的开始
- 浅谈arduino的bootloader
- arduino的定时中断
- arduino 程序的机制
- arduino的介绍
- arduino servo的用法
- Android 开发 对话框Dialog dismiss和hide方法的区别
- unity3D 物体 旋转
- Android TextView设置个别字体样式
- 破解MyEclipse10.7.1版本
- LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
- arduino的String类
- IOS学习之十七:Grand Central Dispatch(GCD)编程基础
- 虚拟机与主机间的复制粘贴
- 【Java集合源码剖析】TreeMap源码剖析
- Junit指定测试执行顺序
- 支持向量机的前世与今生
- go语言解析xml
- Android---recovery 资料搜集
- 单链表的java实现即链表的常见操作