Z
Zombie
Hi, what is the correct way of converting contents of a <string> to
lowercase?
There are no methods of <string> class to do this so I fallback on
strlwr().
But the c_str() method returns a const pointer which cannot be used
with strlwr() as it does the conversion inplace. So, I use the
following logic of copying the contents to a dynamically allocated
char* array and then doing the conversion:
-----------------------------
string str = "faLSe";
char* pc_str = NULL;
pc_str = new char[str.length() + 1];
memset(pc_str, 0, sizeof(pc_str));
strcpy(pc_str, str.c_str());
strlwr(pc_str);
// pc_str now contains "false"
lowercase?
There are no methods of <string> class to do this so I fallback on
strlwr().
But the c_str() method returns a const pointer which cannot be used
with strlwr() as it does the conversion inplace. So, I use the
following logic of copying the contents to a dynamically allocated
char* array and then doing the conversion:
-----------------------------
string str = "faLSe";
char* pc_str = NULL;
pc_str = new char[str.length() + 1];
memset(pc_str, 0, sizeof(pc_str));
strcpy(pc_str, str.c_str());
strlwr(pc_str);
// pc_str now contains "false"