我需要從字符串中刪除一些字符。當我使用擦除它不起作用,編譯錯誤擦除沒有任何成員命名。請幫幫我。 Probaly是因爲我爲Arduino UNO寫的。從字符串中刪除字符C++/Arduino UNO
回答
Arduino String
類與std::string完全不同。例如erase
不存在。但有方法remove
。
無論如何,你應該這樣開始:https://www.arduino.cc/en/Reference/HomePage
中的Arduino的圖書館爲了因素目標微控制器的內存約束定製。例如,Uno在mega328P Atmel(現爲Microchip)器件上運行,該器件僅具有32 KB閃存。
那麼如何使用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.
}
只知道其實,用一個參數去除也刪除了其餘的字符串。如果你只想刪除一個字符,你必須使用帶有兩個參數的變體。它可能從1索引,而不是從0; – KIIV
@KIIV謝謝!更正 – NonCreature0714
@KIIV你如何判斷它是否從'1'而不是'0'索引? – NonCreature0714
- 1. 從字符串中刪除字符串
- 2. 從字符串中刪除字符串
- 3. VB.NET - 從字符串中刪除字符
- 4. 從c字符串中刪除字符
- 5. 從字符串中刪除Unicode字符
- 6. 從字符串中刪除字符
- 7. 從Java字符串中刪除字符
- 8. 從字符串中刪除字符C
- 9. datagridview從字符串中刪除'&'字符
- 10. C從字符串中刪除字符
- 11. 從字符串中刪除字符
- 12. Fortran:從字符串中刪除字符
- 13. jQuery從字符串中刪除' - '字符
- 14. 從字符串中刪除字符?
- 15. 從字符串中刪除字符
- 16. Python:從字符串中刪除字符
- 17. 從字符串中刪除字符[i]
- 18. C++從字符串中刪除字符
- 19. 從C字符串中刪除字符
- 20. 從字符串中刪除
- 21. 從字符串中刪除()
- 22. 從字符串中刪除「
- 23. 從字符串中刪除「@」
- 24. 如何從字符串中刪除動態字符字符串?
- 25. 使用擦除和刪除從字符串中刪除字符
- 26. 刪除軟連字符從字符串
- 27. SQL從字符串刪除字符
- 28. 從android字符串刪除空字符
- 29. 從字符串末尾刪除字符
- 30. 從SQL字符串的字符刪除
也許在Arduino的他們有不同的功能。 –