2016-10-17 282 views
-1

我需要從字符串中刪除一些字符。當我使用擦除它不起作用,編譯錯誤擦除沒有任何成員命名。請幫幫我。 Probaly是因爲我爲Arduino UNO寫的。從字符串中刪除字符C++/Arduino UNO

+0

也許在Arduino的他們有不同的功能。 –

回答

0

中的Arduino的圖書館爲了因素目標微控制器的內存約束定製。例如,Uno在mega328P Atmel(現爲Microchip)器件上運行,該器件僅具有32 KB閃存。

+0

那麼如何使用remove函數呢? –

0

擴展在什麼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. 
} 
+0

只知道其實,用一個參數去除也刪除了其餘的字符串。如果你只想刪除一個字符,你必須使用帶有兩個參數的變體。它可能從1索引,而不是從0; – KIIV

+0

@KIIV謝謝!更正 – NonCreature0714

+0

@KIIV你如何判斷它是否從'1'而不是'0'索引? – NonCreature0714