从字符串c++/Arduino UNO删除字符
Remove character from String c++/Arduino UNO
我需要从字符串中删除一些字符。当我使用擦除它不工作,编译错误擦除没有成员命名。请帮帮我。可能是因为我写的是Arduino UNO
Arduino String
class与std::string有很大不同。例如,erase
不存在。但还有remove
方法
扩展KIIV的建议,您可以这样做:
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
String words = "This is a sentence."; //reassign same string at the start of loop.
delay(1000);
Serial.println(words);
char c;
char no = ' '; //character I want removed.
for (int i=0; i<words.length()-1;++i){
c = words.charAt(i);
if(c==no){
words.remove(i, 1);
}
}
Serial.println(words);
delay(5000);//5 second delay, for demo purposes.
}
Arduino中的库是定制的,以便考虑目标微控制器的内存约束。例如,Uno运行在mega328P的Atmel(现在的Microchip)设备上,该设备只有32kb的闪存。
相关文章:
- 将数组的地址分配给变量并删除
- 删除一个线程上有数百万个字符串的大型哈希映射会影响另一个线程的性能
- C/C++编译器通常会删除重复的库吗
- 从链接列表c++中删除一个项目
- C++如何通过用户输入删除列表元素
- Ardunio UNO解决了多个重叠的定时器循环
- 为什么在C++中使用私有复制构造函数与删除复制构造函数
- 是否需要删除包含对象的"pair"?
- 如何在自删除后将对象设置为nullptr
- 迭代时从向量和内存中删除对象
- 使用函数"remove"删除重复元素
- 如何从多映射中删除特定的重复项
- 运算符C++ "delete []"仅删除 2 个前值
- 删除指向指针的指针是运行时错误吗
- 将指针设置为"nullptr"并不能防止双重删除?
- 为什么示例代码访问IUnknown中已删除的内存
- 如何通过 getter 函数删除矢量的元素?
- 从控制台中删除最后打印的元素
- C++中的线程安全删除
- 从字符串c++/Arduino UNO删除字符