Wiringprogrammingreference

Page 62

62 Robo-Creator :



2.6.3.5 replace() เปนคําสั่งแทนทีตั่ วอักษรใน string (char1) ดวยตัวอักษรที่กําหนดไว (char1) รูปแบบ :

string.replace(char1, char2) โดยที่ char1 คือ ตัวอักษรทีต่ องการคนหาเพื่อแทนที่ ตองเปนขอมูลชนิด char char2 คือ ตัวอักษรทีต่ องการนําไปแทนที่ ตองเปนขอมูลชนิด char string คือตัวแปร String class ตัวอยางที่ 2-28 String str = “WWWX”; void setup() { Serial.begin(9600); // ตังค ้ าอัตราบอดใหกับโมดูลสื่อสารขอมูลผานพอรตอนุกรมเปน 9600 str.replace(‘W’,’1'); // แทนที่อักษร W ทุกตัวดวยเลข 1 Serial.println(str); // ทีหน ่ าตาง Serial monitor ของ Wiring IDE จะแสดงขอความ 111X } void loop() {}


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.