Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Trying to convert to upper case?

Posted on 2000-02-28
7
754 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

840 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