Function to Use String
Dependencies: mbed
main.cpp@1:906bda113ceb, 2015-11-13 (annotated)
- Committer:
- sweilz
- Date:
- Fri Nov 13 08:12:39 2015 +0000
- Revision:
- 1:906bda113ceb
- Parent:
- 0:624614538ca8
String in Mbed
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sweilz | 0:624614538ca8 | 1 | #include "mbed.h" |
sweilz | 0:624614538ca8 | 2 | #include <string> |
sweilz | 0:624614538ca8 | 3 | |
sweilz | 0:624614538ca8 | 4 | Serial pc(SERIAL_TX, SERIAL_RX); |
sweilz | 0:624614538ca8 | 5 | |
sweilz | 0:624614538ca8 | 6 | int main() |
sweilz | 0:624614538ca8 | 7 | { |
sweilz | 1:906bda113ceb | 8 | |
sweilz | 0:624614538ca8 | 9 | string txt("Hello World My Name is Liews"); |
sweilz | 0:624614538ca8 | 10 | string str; |
sweilz | 0:624614538ca8 | 11 | |
sweilz | 0:624614538ca8 | 12 | //txt.clear(); //Clear String |
sweilz | 0:624614538ca8 | 13 | //int x = txt.empty(); // return 1 if String is Empty |
sweilz | 0:624614538ca8 | 14 | |
sweilz | 0:624614538ca8 | 15 | //pc.printf("size: %d\n",txt.size()); // return size of string |
sweilz | 0:624614538ca8 | 16 | //pc.printf("length: %d\n",txt.length()); //return size od string |
sweilz | 0:624614538ca8 | 17 | |
sweilz | 0:624614538ca8 | 18 | //pc.printf("operator[]: %c\n",txt[10]); //access to charecter in string |
sweilz | 0:624614538ca8 | 19 | //pc.printf("at: %c\n",txt.at(10)); //access to charecter in string |
sweilz | 0:624614538ca8 | 20 | |
sweilz | 0:624614538ca8 | 21 | //txt += " Tong"; // add string to string |
sweilz | 0:624614538ca8 | 22 | //txt.append("s"); // add string to string |
sweilz | 0:624614538ca8 | 23 | //txt.push_back('K');// add charecter to string |
sweilz | 0:624614538ca8 | 24 | |
sweilz | 0:624614538ca8 | 25 | //str.assign(txt,15,4); //split string at index first and length |
sweilz | 0:624614538ca8 | 26 | //str.assign("Chawanluck Martchan",10); // cut string by length |
sweilz | 0:624614538ca8 | 27 | //str.assign("Hello"); // assign string |
sweilz | 0:624614538ca8 | 28 | //str.assign(10,'*'); // make string ********** |
sweilz | 0:624614538ca8 | 29 | |
sweilz | 0:624614538ca8 | 30 | |
sweilz | 0:624614538ca8 | 31 | |
sweilz | 0:624614538ca8 | 32 | |
sweilz | 0:624614538ca8 | 33 | |
sweilz | 0:624614538ca8 | 34 | pc.printf("string txt: %s\n",txt.c_str()); |
sweilz | 0:624614538ca8 | 35 | pc.printf("string txt: %s\n",txt.c_str()); |
sweilz | 0:624614538ca8 | 36 | } |