STL string to upper/lower case 
Author Message
 STL string to upper/lower case

I am trying to convert an STL string to all upper or lower case using
other STL resources if possible.  What is the best/proper way to do
this.

Thanks,
  Mark



Mon, 25 Oct 1999 03:00:00 GMT  
 STL string to upper/lower case


Quote:
> I am trying to convert an STL string to all upper or lower case using
> other STL resources if possible.  What is the best/proper way to do
> this.

Here's one way, untested off the top of my head. Probably not quite
right, but it ought to give you the general idea:

#include <algorithm>
#include <string>
#include <cstdlib> //??

using namespace std;
...
string low;
...
transform (low.begin(), low.end(), ptr_fun(to_upper));
...
--

http://www.ziplink.net/~danm



Tue, 26 Oct 1999 03:00:00 GMT  
 STL string to upper/lower case

Thank you Dan, your example triggered the below solution:

string              x("THIS IS A TEST");
string::iterator    z;

                    // To convert to lower case
                    z = x.begin();
                    transform (x.begin(),x.end(), z,tolower);

                    // To convert to upper case
                    transform (x.begin(),x.end(), z,toupper);

Quote:


> > I am trying to convert an STL string to all upper or lower case using
> > other STL resources if possible.  What is the best/proper way to do
> > this.

> Here's one way, untested off the top of my head. Probably not quite
> right, but it ought to give you the general idea:

> #include <algorithm>
> #include <string>
> #include <cstdlib> //??

> using namespace std;
> ...
> string low;
> ...
> transform (low.begin(), low.end(), ptr_fun(to_upper));
> ...
> --

> http://www.ziplink.net/~danm



Tue, 26 Oct 1999 03:00:00 GMT  
 STL string to upper/lower case


Quote:
> Thank you Dan, your example triggered the below solution:

> string                 x("THIS IS A TEST");
> string::iterator    z;

>                // To convert to lower case
>                     z = x.begin();
>                     transform (x.begin(),x.end(), z,tolower);

>                // To convert to upper case
>                     transform (x.begin(),x.end(), z,toupper);

Cool! I figured all you needed was a nudge in the right direction. <g>

I *really* like the generic algorithms of the STL. Very concise, and
usually very efficient.

--

http://www.ziplink.net/~danm



Tue, 26 Oct 1999 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. moving upper case names to lower case

2. Upper case / lower case problem in IDL file

3. Fastest way to convert lower to upper case?

4. Upper and lower case words

5. Select returning UPPER & LOWER CASE

6. upper/lower case with VMS C

7. strings: lower & upper

8. convert string to Upper case

9. Converting Strings to Upper Case

10. testing 'string' for upper-case letters

11. Change a foreign language string to upper case

12. How to get the upper case of a string

 

 
Powered by phpBB® Forum Software