# string

***

**1. String Creation**

```cpp
std::string str1 = "Hello, World!";  // Initializing with a literal
std::string str2(10, 'a');  // Initializing with a character repeated 10 times
```

**2. String Concatenation**

```cpp
std::string str1 = "Hello";
std::string str2 = ", World!";
std::string str3 = str1 + str2;  // Concatenating str1 and str2
```

**3. String Comparison**

```cpp
std::string str1 = "Apple";
std::string str2 = "Orange";
bool result = (str1 == str2);  // Comparing str1 and str2
```

**4. String Search**

```cpp
std::string str = "This is a sample string";
size_t pos = str.find("sample");  // Finding the first occurrence of "sample"
```

**5. String Replacement**

```cpp
std::string str = "Replace this";
str.replace(0, 6, "Something else");  // Replacing the first 6 characters
```

**6. String Extraction**

```cpp
std::string str = "This is a sample string";
std::string substring = str.substr(5, 5);  // Extracting the substring starting at index 5 for 5 characters
```

**7. String Conversion**

```cpp
std::string str = "123";
int number = std::stoi(str);  // Converting the string to an integer
```

**8. String Formatting**

```cpp
std::string str = std::format("The number is %d", 10);  // Formatting a string using sprintf syntax
```

**9. String Tokenization**

```cpp
std::string str = "Hello, World!";
std::vector<std::string> tokens;
std::istringstream(str) >> tokens;  // Tokenizing the string into a vector
```

**10. String Uppercase/Lowercase**

```cpp
std::string str = "Hello";
str.to_upper();  // Converting to uppercase
str.to_lower();  // Converting to lowercase
```

**11. String Trim**

```cpp
std::string str = "  Hello, World!  ";
str.trim();  // Trimming leading and trailing whitespace
```

**12. String Split**

```cpp
std::string str = "Hello,World,How,Are,You";
std::vector<std::string> parts = split(str, ',');  // Splitting the string by commas
```

**13. String Join**

```cpp
std::vector<std::string> words = {"Hello", "World", "How", "Are", "You"};
std::string result = join(words, ",");  // Joining the vector into a comma-separated string
```

**14. String Comparison (STL)**

```cpp
std::string str1 = "Apple";
std::string str2 = "Orange";
bool result = (str1 < str2);  // Comparing str1 and str2 using STL lexicographical comparison
```

**15. String Validation**

```cpp
std::string str = "Hello, World!";
bool valid = std::regex_match(str, std::regex("[a-zA-Z0-9 ]+"));  // Validating the string using a regular expression
```

**16. String Hashing**

```cpp
std::string str = "Hello, World!";
size_t hash = std::hash<std::string>()(str);  // Hashing the string using the STL hash function
```

**17. String Encapsulation**

```cpp
class Person {
public:
    std::string name;
    // Constructor, getter, setter
};
```

**18. String Manipulation in Loop**

```cpp
for (int i = 0; i < str.length(); i++) {
    // Do something with str[i]
}
```

**19. String Iteration with Range-Based For Loop**

```cpp
for (char ch : str) {
    // Do something with ch
}
```

**20. String Search with Regular Expression**

```cpp
std::regex pattern("world", std::regex::icase);
if (std::regex_search(str, pattern)) {
    // Do something
}
```

**21. String Formatting with Format Specifiers**

```cpp
std::string formatted = std::format("%s %d", "Hello", 10);
```

**22. String Utility Headers**

```cpp
#include <string>
#include <sstream>
#include <regex>
```

**23. String Reversal**

```cpp
std::string str = "Hello, World!";
std::reverse(str.begin(), str.end());
```

**24. String Rot13 Encryption**

```cpp
std::string rot13(const std::string& str) {
    std::string result;
    for (char ch : str) {
        if (ch >= 'a' && ch <= 'z') {
            result += ((ch - 'a' + 13) % 26) + 'a';
        } else if (ch >= 'A' && ch <= 'Z') {
            result += ((ch - 'A' + 13) % 26) + 'A';
        } else {
            result += ch;
        }
    }
    return result;
}
```

**25. String Character Count**

```cpp
std::map<char, int> char_counts;
for (char ch : str) {
    char_counts[ch]++;
}
```

**26. String Palindrome Check**

```cpp
bool is_palindrome(const std::string& str) {
    std::string reversed = str;
    std::reverse(reversed.begin(), reversed.end());
    return str == reversed;
}
```

**27. String Vector**

```cpp
std::vector<std::string> str_vector = {"Hello", "World", "How", "Are", "You"};
```

**28. String List**

```cpp
std::list<std::string> str_list = {"Hello", "World", "How", "Are", "You"};
```

**29. String Set**

```cpp
std::set<std::string> str_set = {"Hello", "World", "How", "Are", "You"};
```

**30. String Map**

```cpp
std::map<std::string, int> str_map = {{"Hello", 1}, {"World", 2}, {"How", 3}, {"Are", 4}, {"You", 5}};
```

**31. String Anagram**

```cpp
bool is_anagram(const std::string& str1, const std::string& str2) {
    if (str1.size() != str2.size()) {
        return false;
    }
    std::unordered_map<char, int> char_counts;
    for (char ch : str1) {
        char_counts[ch]++;
    }
    for (char ch : str2) {
        if (char_counts[ch] == 0) {
            return false;
        }
        char_counts[ch]--;
    }
    return true;
}
```

**32. String Longest Common Prefix**

```cpp
std::string longest_common_prefix(const std::vector<std::string>& strs) {
    if (strs.empty()) {
        return "";
    }
    std::string prefix = strs[0];
    for (int i = 1; i < strs.size(); i++) {
        while (strs[i].find(prefix) != 0) {
            prefix = prefix.substr(0, prefix.size() - 1);
        }
    }
    return prefix;
}
```

**33. String Isogram**

```cpp
bool is_isogram(const std::string& str) {
    std::set<char> char_set;
    for (char ch : str) {
        if (char_set.find(ch) != char_set.end()) {
            return false;
        }
        char_set.insert(ch);
    }
    return true;
}
```

**34. String Pangram**

```cpp
bool is_pangram(const std::string& str) {
    std::set<char> char_set;
    for (char ch = 'a'; ch <= 'z'; ch++) {
        char_set.insert(ch);
    }
    for (char ch : str) {
        if (char_set.find(ch) != char_set.end()) {
            char_set.erase(ch);
        }
    }
    return char_set.empty();
}
```

**35. String Zigzag Conversion**

```cpp
std::string convert(const std::string& str, int num_rows) {
    if (num_rows == 1) {
        return str;
    }
    std::vector<std::string> rows(num_rows);
    int row = 0;
    int direction = 1;
    for (char ch : str) {
        rows[row += direction] += ch;
        if (row == 0 || row == num_rows - 1) {
            direction *= -1;
        }
    }
    std::string result;
    for (const std::string& row : rows) {
        result += row;
    }
    return result;
}
```

**36. String Wildcard Matching**

```cpp
bool is_wildcard_match(const std::string& str, const std::string& pattern) {
    int i = 0;


```
