Advertisement

String toupper?

Started by May 10, 2001 01:29 AM
4 comments, last by SikCiv 23 years, 9 months ago
Is there a toupper function in vc for string or do I have to use toupper on each character manually?

  Downloads:  ZeroOne Realm

I do not know of a VC function that does this for you. If you have a null terminated string, it shouldnt really add too much overhead to do each character separately:
  // char* str is the stringfor(char* p=str; p && *p != ''\0''; p++)   // call touppper function here, using current char *p  
Advertisement
void strupr(char *str)
{
for (; *str != ''\0''; str++)
if ((*str >= ''a'') && (*str <= ''z'')) *str += ''A''-''a'';
}
the original strupr returns a pointer to the new string, you could do it too
i just show you the idea

Arkon
[QSoft Systems]
  std::transform(Text.begin(), Text.end(), Text.begin(),toupper);  


Cool huh? I think it might have been stoffel who showed me this...
Chris Brodie
Is the Text variable an MFC class or something? The thing is Ive tried to include stdafx in my game but it gave me loads of errors including one that says you cannot include stdafx with winmain.h so im trying to avoid MFC classes.

I have found a solution anyway, basically I needed to compare to string without being case sensitive, I used strcmp which gave me a non zero value if the strings were the same but had some letters in upper case, I found out that there was a function that compares two string without case checking called stricmp and it works and all is fine.

  Downloads:  ZeroOne Realm

Sorry, Text would be
std::string Text;

you need to include :

#include
#include
#include
Chris Brodie

This topic is closed to new replies.

Advertisement