Function to Use String

Dependencies:   mbed

Committer:
sweilz
Date:
Fri Nov 13 08:02:37 2015 +0000
Revision:
0:624614538ca8
Child:
1:906bda113ceb
String in mbed F411RE

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sweilz 0:624614538ca8 1 #include "mbed.h"
sweilz 0:624614538ca8 2 #include <string>
sweilz 0:624614538ca8 3 //------------------------------------
sweilz 0:624614538ca8 4 // Hyperterminal configuration
sweilz 0:624614538ca8 5 // 9600 bauds, 8-bit data, no parity
sweilz 0:624614538ca8 6 //------------------------------------
sweilz 0:624614538ca8 7
sweilz 0:624614538ca8 8 Serial pc(SERIAL_TX, SERIAL_RX);
sweilz 0:624614538ca8 9
sweilz 0:624614538ca8 10
sweilz 0:624614538ca8 11 int main()
sweilz 0:624614538ca8 12 {
sweilz 0:624614538ca8 13 //char* txt[]={"Hello\n","World","My Name is Liews"};
sweilz 0:624614538ca8 14
sweilz 0:624614538ca8 15 string txt("Hello World My Name is Liews");
sweilz 0:624614538ca8 16 string str;
sweilz 0:624614538ca8 17
sweilz 0:624614538ca8 18 //txt.clear(); //Clear String
sweilz 0:624614538ca8 19 //int x = txt.empty(); // return 1 if String is Empty
sweilz 0:624614538ca8 20
sweilz 0:624614538ca8 21 //pc.printf("size: %d\n",txt.size()); // return size of string
sweilz 0:624614538ca8 22 //pc.printf("length: %d\n",txt.length()); //return size od string
sweilz 0:624614538ca8 23
sweilz 0:624614538ca8 24 //pc.printf("operator[]: %c\n",txt[10]); //access to charecter in string
sweilz 0:624614538ca8 25 //pc.printf("at: %c\n",txt.at(10)); //access to charecter in string
sweilz 0:624614538ca8 26
sweilz 0:624614538ca8 27 //txt += " Tong"; // add string to string
sweilz 0:624614538ca8 28 //txt.append("s"); // add string to string
sweilz 0:624614538ca8 29 //txt.push_back('K');// add charecter to string
sweilz 0:624614538ca8 30
sweilz 0:624614538ca8 31 //str.assign(txt,15,4); //split string at index first and length
sweilz 0:624614538ca8 32 //str.assign("Chawanluck Martchan",10); // cut string by length
sweilz 0:624614538ca8 33 //str.assign("Hello"); // assign string
sweilz 0:624614538ca8 34 //str.assign(10,'*'); // make string **********
sweilz 0:624614538ca8 35
sweilz 0:624614538ca8 36
sweilz 0:624614538ca8 37
sweilz 0:624614538ca8 38
sweilz 0:624614538ca8 39
sweilz 0:624614538ca8 40 pc.printf("string txt: %s\n",txt.c_str());
sweilz 0:624614538ca8 41 pc.printf("string txt: %s\n",txt.c_str());
sweilz 0:624614538ca8 42 }