#include<iostream>
#include<string>
int main()
{
// the two strings to concatenate
std::string str1 = "Hello ";
std::string str2 = "world!";
// allocate memory to the concatenated string with null-terminator
char* str3 = new char[str1.size() + str2.size() + 1];
// initialise a moving pointer
char* p = str3;
// copy from the first string
memcpy( p, str1.c_str(), str1.size() );
// advance the pointer
p += str1.size();
// copy from the second string
memcpy( p, str2.c_str(), str2.size() );
// advance the pointer
p += str2.size();
// set the null-terminator
*p = 0;
// print concatenated string
std::cout << str3 << std::endl;
// tidy up
delete [] str3, str3 = NULL;
}
Use "+". Example: String string = "does this answer " + "your question?";
v can concatenate two string by using a function like: select CONCAT( CONCAT('ename','e_mrks'),"name","marks" from student;
Concat()
public class class1{public void changeCase(String str){String str1=str.toUpperCase();String str2=str.toLowerCase();System.out.println(str1);System.out.println(str2);System.out.println("After concatenation "+("to".concat("get").concat("her")));}public static void main(String[] args){class1 c1=new class1();c1.changeCase("Hello");}}
performing string operation using pointers
String library function is one which is used to perform an operation in C-programming,without which library functions likestrlen(),strcp(),strcmp(),strdup(),strrev(),etc..,.can be performed
jst subtract 32 from first character of string to convert it into capital
You can create a separate string initially empty. Then using a loop, start at the end of the string and add it to the end of the other string. At the end of the loop, the other string would contain the reverse.
#include<iostream> #include<string> int main() { using std::string; string a = "hand"; string b = "bag"; string c = a + b; // concatenation }
All these are conversion functions - atoi()-string to integer.itoa()-integer to string.gcvt()-double to string
You can use "string" class in C++ for string operations or you may use c style string functions as well. #include <string> String class in C++ provides all basic function to operate on strings. you may details descriptin at http://www.cplusplus.com/reference/string/string/
define class string