Solved

Trying to convert to upper case?

Posted on 2000-02-28
7
753 Views
Last Modified: 2008-02-26
I have the following code.  I need to make sure that is in upper case.  How do you do this with basic_string:

typedef basic_string<TCHAR> CStr;

Then somewhere in my function I do the
following:

CStr strDriveSelected;

strDriveSelected = OLE2T( strDrive );

What is the best way to conver it to
an upper case.  So if strDrive is "a"
strDriveSelected becomes "A"

THanks
0
Comment
Question by:eric07
7 Comments
 
LVL 2

Expert Comment

by:vbk_bgm
ID: 2567934
Method 1
You can use CharUpperBuff(LPTSTR lpsz,
DWORD length) to convert the string into uppercase
Method 2
Use CString::MakeUpper to convert the string into uppercase after assigning it to a CString variable.
0
 

Author Comment

by:eric07
ID: 2567943
I'm not using MFC.  My project is an ATL not MFC based.  Is there an ANSII function to do this?

Thanks
0
 
LVL 5

Expert Comment

by:proskig
ID: 2568033
Hi,
This code should help you:
_tcsupr(const_cast<TCHAR*>(strDriveSelected.data()));

Regards,
Igor
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 33

Accepted Solution

by:
hongjun earned 20 total points
ID: 2568083
#include <ctype.h>
#include <stdio.h>

void main()
{
....
  strDriveSelected = toupper(strDrive);
....
}
0
 
LVL 22

Expert Comment

by:nietod
ID: 2568340
>> This code should help you:
>> _tcsupr(const_cast<TCHAR*>(strDriveSelected.data()));
Not really!  Don't ever do that.  That can mess up other strings.
0
 
LVL 1

Expert Comment

by:JMu
ID: 2569348
Please, don't use toupper. It doesn't work in Finland for example. We have letters like åäö and their uppercase equivalents ÅÄÖ.

toupper works only for a to z.

JMu
0
 
LVL 22

Expert Comment

by:nietod
ID: 2569407
The STL toupper() template function allows you to specify a locale so that this can be made to work in any language (and with any character representation.)
0

Featured Post

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question