从字符串中删除字符 c++/Arduino UNO
Remove character from String c++/Arduino UNO
我需要从字符串中删除一些字符。当我使用 erase 时它不起作用,编译错误 erase no member named.请帮我。可能是因为我为 Arduino UNO 写作。
Arduino String
class is quite different from std::string. For example erase
doesn't exists. But there is method remove
.
开始
Arduino 中的库是定制的,以考虑目标微控制器的内存限制。例如,Uno 在 mega328P Atmel(现为 Microchip)设备上运行,该设备只有 32 KB 闪存。
扩展 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.
}
我需要从字符串中删除一些字符。当我使用 erase 时它不起作用,编译错误 erase no member named.请帮我。可能是因为我为 Arduino UNO 写作。
Arduino String
class is quite different from std::string. For example erase
doesn't exists. But there is method remove
.
Arduino 中的库是定制的,以考虑目标微控制器的内存限制。例如,Uno 在 mega328P Atmel(现为 Microchip)设备上运行,该设备只有 32 KB 闪存。
扩展 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.
}