I have this function.
void cast(char *buf)
{
string str(buf);
string s=str.substr(0,5);
std::transform(s.begin(), s.end(), s.begin(),::toupper);
DemoInput=s;
}
The *buf is a message that the client sends. I’m trying to take that message and no matter how long it is strip it to five characters and make it uppercase. This works if the message > 5 but if the message < 5 then there are garbage characters at the end of it.
ex: if buf is “long” then DemoInput becomes “LONG\\r”
I thought about using regex (“[:upper:]”) but think there must be an easier way to do this.
I find posix regex a bit more complicated then python regex for example.
If you only need the first 5 characters, don’t copy the whole of
buf. That just wastes space and time. Also, you shouldn’t copy anything past the telnet control character\r.