#include <iostream>
#include <string>
int main() {
// Create a string object
std::string str = "Hello, World!";
// Get the length of the string
std::cout << "The length of the string is: " << str.length() << std::endl;
// Find the position of a substring within the string
std::cout << "The position of 'World' in the string is: " << str.find("World") << std::endl;
// Replace a substring within the string
str.replace(str.find("World"), 5, "Universe");
std::cout << "The modified string is: " << str << std::endl;
// Extract a substring from the string
std::string substr = str.substr(str.find(",") + 2, 6);
std::cout << "The extracted substring is: " << substr << std::endl;
return 0;
}
output :
The length of the string is: 14
The position of 'World' in the string is: 7
The modified string is: Hello, Universe!
The extracted substring is: Universe
0 Comments