how remove null character from string

Hi All,

I couldn't find an specific answer to my problem. I have a char array which I converted to a string so I could find a substring.
If the substring match a requirement the original char array should change and it would be printed via cout.
Example:

Original char array: "msg: this is a message"
Requirement: start with "msg:"
If it matches return "I received msg: this is a message --received"

but when I print that I see the following:

"I received msg: this is a message^%$^% --received"

If there is a correct way to do this I would greatly appreciate some advice.

Thanks!
std::string has a constructor that takes a null-terminated C-string as an argument.

1
2
char arr[] = "This is a C-string";
std::string string(arr);
What's your code for: "... the original char array should change ...", I mean, how do you "change" the char array currently?

Or you skip the char[] -> string conversion and search the char array directly with strncmp()
The original char array actually doesn't matter , but I need to return a char array like I explained before, this means some characters before and after the original array.
I'll try that suggestion tonight and give you an answer.
Thanks for the help
If you work with char[] try strcat() or strncat() to join two strings together.
With std:string just use the + operator.
std::string has two methods for returning the internal char array. Look at c_str() and data().
Perfect, thanks ResidentBiscuit. Now I got into another issue related which I'll post as a new question so I don't mess things up.
Topic archived. No new replies allowed.