i have
cost char* a="test_r.txt" i want to strip the _r and add _n instead of it so that it becomes "test_n.txt" and save it in const char* b;
what is the easiest way to do it ?
Like mentioned before, if you put your const char * into a std::string, you can change your characters. Regarding the replacing of a constant that is longer than one character you can use the find method of std::string:
const char *a = "test_r_or_anything_without_r.txt"; std::string a_copy(a); std::string searching("_r"); std::string replacing("_n"); size_t pos_r = 0; while (std::string::npos != (pos_r = a_copy.find(searching, pos_r))) { a_copy.replace(a_copy.begin() + pos_r, a_copy.begin() + pos_r + searching.length(), replacing.begin(), replacing.end()); } const char *b = a_copy.c_str();
std::string. You can't modify the contents of string literals.