Hello,
I'm building an agenda in MFC.
I use some EditControl boxes that have CString variables attached to them.
I want to process the data that is inserted in a way that a string that looks like:
"bILL gATES" will become "Bill Gates" - capitalize every first letter and make lower the others.
At the first i tried to just capitalize the first letter.
The problem is that CString has functions just for making all the string in lowercase or uppercase,
If i'm trying for a variable CString name:
name[0]=towupper(name[0]);
i get: "Expression must be a modifiable lvalue";
so i've converted CString data to wchar_t ( i need it wchar_t to support UTF-8 characters)
The big issue is that i cannot declare the wchar_t variable like : wchar_t name2 [nr_of_characters],
because the CString length for name can be variable, so i've tried something like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
void Agenda::Format (CString& name)
{
bool first=true;//if its the first letter of every word
int i;
wchar_t name2=(wchar_t)LPCTSTR(name);// converts CString to wchar_t;
for (i = 0; i < wcslen(&name2)+1; i++)
{
if (iswspace(name2[i]))//if its a space goes to the next character
{
first=true;
continue;
}
if (first == true)
{
name2[i] = towupper(name2[i]);
first = false;
}
}
}
|
it doesn't work, i get an error for "name2[i]" : "expression must have pointer to object type"
I have run out of ideas and i have to finish this for school.
This is the last thing that i have to implement for the agenda.
If anyone has some ideas it would be great.