如何在 Arduino 字符串的开头添加元素.类似于 JS unshift();
How to add elements at the beginning of an Arduino String. Similar to JS unshift();
我有一个未知大小String
,但最大大小为 8,我想通过在字符串开头添加 0(零(来确保其大小始终为 8。
例如,输入的String
是"5687",我必须加 0 直到它的大小为 8:"00005687"。
String str = "5687";
while(str.length() < 8) {
// add 0 at the beginning of str
}
与JavaScript不同,Arduino C++没有像unshift((这样的东西,或者它有吗?
我怎样才能实现我的目标?谢谢。
PS:我使用的是 ESP32,只有几个字符串,因为 ESPAsyncWebServer 的处理程序通常会返回字符串参数。
String str = "5687";
while(str.length() < 8) {
str = String("0") + str;
}
相关文章:
- 类似于strcat()的函数出现问题
- 如何将C++闭包与变量参数同时重用——类似于JavaScript
- 算术运算的结果类似于:C浮点变量中的1/3
- 在数组中输入 n 个整数的列表,并以类似于钟摆来回移动的方式排列它们. 输入-1 3 2 5 4,输出5 3 1 2 4
- 创建类似于布尔值的变量类型
- 如何在 Arduino 字符串的开头添加元素.类似于 JS unshift();
- Java 中是否有类似于 C++ 中引用类型"&"的内容?
- C++未知长度字符串的数组,其行为类似于 Python 字符串列表
- 如何创建类似于 QVariant 的变体类
- 对于多个字符(如 ETX/STX 对),是否有类似于 std::quote 的东西
- 初始化命名空间中的变量是否类似于将它们初始化为类成员?
- C++中用于结构的纯数组的类似于TableView/DataFrame的通用功能
- 有没有类似于stoi的函数可以用于模板类
- 如何编写一个类似于kernellist_head的c++风格的双链表实现
- 序列化模式类似于boost::序列化
- 构造一个类似于JSON文件c++的字符串
- 多重继承中的派生类的行为类似于聚合
- 如何使更安全的C++变体访问者,类似于切换语句?
- C++ Python 中是否有类似于 help() 的函数
- 在c++11中,类似于node.js/javascript回调的线程