473,587 Members | 2,533 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

STL string - converting to low case

Hi!

I have a STL string, which I need to convert to low case.
In VC 6 I used:
string sInputBuffer = _strlwr((char*) sBuffer.c_str() );

However, now in MSVC.NET 2005 I am getting a warning, that _strlwr is
depricated. Instead, it's proposed to use _strlwr_s :
http://msdn2.microsoft.com/en-us/library/y889wzfw.aspx

How should I use this new function with STL, if I don't want to
allocate memory on heap.

Thanks.

Vadim

Jan 16 '06 #1
37 22400

Vadim wrote:
Hi!

I have a STL string, which I need to convert to low case.
In VC 6 I used:
string sInputBuffer = _strlwr((char*) sBuffer.c_str() );


Try this maybe (std C++ - don't know about MVC):

std::transform( sBuffer.begin() , sBuffer.end(), sBuffer.begin() ,
::tolower );

Cheers,
Andre

Jan 16 '06 #2

Vadim wrote:
Hi!

I have a STL string, which I need to convert to low case.
In VC 6 I used:
string sInputBuffer = _strlwr((char*) sBuffer.c_str() );

However, now in MSVC.NET 2005 I am getting a warning, that _strlwr is
depricated. Instead, it's proposed to use _strlwr_s :
http://msdn2.microsoft.com/en-us/library/y889wzfw.aspx

How should I use this new function with STL, if I don't want to
allocate memory on heap.


Are you sure you need to convert to lower case? If all you want is
case insensitive comparison you might have a look at char_traits.

Jan 16 '06 #3
Vadim wrote:
I have a STL string, which I need to convert to low case.
In VC 6 I used:
string sInputBuffer = _strlwr((char*) sBuffer.c_str() );
Ugh!
However, now in MSVC.NET 2005 I am getting a warning, that _strlwr is
depricated. Instead, it's proposed to use _strlwr_s :
http://msdn2.microsoft.com/en-us/library/y889wzfw.aspx

How should I use this new function with STL, if I don't want to
allocate memory on heap.


http://groups.google.com/groups?q=co...se&qt_s=Search

V
Jan 16 '06 #4
In article <11************ *********@g14g2 000cwa.googlegr oups.com>,
Vadim <va*******@gmai l.com> wrote:
string sInputBuffer = _strlwr((char*) sBuffer.c_str() );


Ouch. I suggest you look up the definition of _strlwr.

Also, note that c_str() returns a non-modifiable c-style string.
--
Mark Ping
em****@soda.CSU A.Berkeley.EDU
Jan 16 '06 #5
Try this:

struct lowercase_func {
void operator()(std: :string::value_ type& v) { v = tolower(v); }
};
std::string make_lowercase( std::string s) {
for_each(s.begi n(), s.end(), lowercase_func( ));
return s;
}

Jan 17 '06 #6
In message <11************ **********@g49g 2000cwa.googleg roups.com>,
at******@gmail. com writes
Try this:

struct lowercase_func {
void operator()(std: :string::value_ type& v) { v = tolower(v); }
};
std::string make_lowercase( std::string s) {
for_each(s.begi n(), s.end(), lowercase_func( ));
return s;
}

But for_each is intended to be a non-modifying operation. OK, it will
work, but std::transform( s.begin(), s.end(), s.begin(), tolower) would
more clearly express your intention.

--
Richard Herring
Jan 17 '06 #7

ro**********@gm ail.com wrote:
Are you sure you need to convert to lower case? If all you want is
case insensitive comparison you might have a look at char_traits.


and exactly which function of char_traits would you use to do that?

Jan 17 '06 #8
Thanks for your help.
In fact, I do need to make some case insensitive finds, but since some
parts of my original string I will have to convert later to unified
case, I decieded to convert the original string to low case. It seems
that there is no any perfoamnce problem. 250 Kb file in my string is
converted to low case almost without seeing delay in "Step over"
debugging.

I do have perfomance problem with reading from file and I guess you can
help me:
I have a text file, which I read entirely to my string variable.
Originally I made some checks while reading, so my code looks like
that:

ifstream is;
is.open (INPUT_FILE);
string sInputBuffer;

while (is.good())
{
sInputBuffer+= is.get();
}

Now, I just only read the contents of the file to string buffer.
Reading char after char is definitely the bad thing. What would be the
most efficient way of reading the whole file?

Thanks a lot!

Vadim

Jan 17 '06 #9
> >
struct lowercase_func {
void operator()(std: :string::value_ type& v) { v = tolower(v); }
};
std::string make_lowercase( std::string s) {
for_each(s.begi n(), s.end(), lowercase_func( ));
return s;
}

But for_each is intended to be a non-modifying operation. OK, it will
work, but std::transform( s.begin(), s.end(), s.begin(), tolower) would
more clearly express your intention.


You're right, std::transform should probably be used instead. However
(you may already know this) the direct usage of tolower is not
portable. See the discussion at:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11108

Aaron

Jan 17 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
7600
by: karthi | last post by:
hi, I need user defined function that converts string to float in c. since the library function atof and strtod occupies large space in my processor memory I can't use it in my code. regards, Karthi
2
13113
by: Edvin | last post by:
Why is binary array written to a file different than when converting the binary array to string and then writing it to file! For example: // --- Allocate byte array byte arrByte = new byte; for( int i=1; i< arrByte.Length; i++ ) arrByte = (byte)i;
4
5528
by: Russell Warren | last post by:
I've got a case where I want to convert binary blocks of data (various ctypes objects) to base64 strings. The conversion calls in the base64 module expect strings as input, so right now I'm converting the binary blocks to strings first, then converting the resulting string to base64. This seems highly inefficient and I'd like to just go...
2
11146
by: Brian Parker | last post by:
I am beginning to work with VB2005.NET and I'm getting some problems with string formatting converting an application from VB6. VB6 code:- sTradeDate = Format(pArray(4,i Record), "mmddyy") pArray is a variant array containing a date string at pArray(4, iRecord) in the format "yyyy/mm/dd"
21
55600
by: phpCodeHead | last post by:
Code which should allow my constructor to accept arguments: <?php class Person { function __construct($name) { $this->name = $name; } function getName()
14
24253
by: Mosfet | last post by:
Hi, what is the most efficient way of doing a case insensitive comparison ? I am trying to write a universal String class and I am stuck with the case insensitive part : TCHAR is a char in MultiByte String env (MBCS) and wchar_t if UNICODE #if defined(WIN32) || defined(UNDER_CE)
16
8173
by: gaga | last post by:
my function should accept a pointer to a string as its argument. and it should convert each charater to an uppercase letter. I know what i need to do, its just my syntax is all out of whack. void strUpper (char *myStr) { int i; strcpy (*myStr); for(i=0; myStr; i++) {
4
8233
by: J Peyret | last post by:
Well, as usual I am confused by unicode encoding errors. I have a string with problematic characters in it which I'd like to put into a postgresql table. That results in a postgresql error so I am trying to fix things with <string>.encode he Company�s ticker Trying for an encode:
14
2524
by: Jamenson | last post by:
Hi everyone! I want to convert strings like "LEONARDO DI CAPRIO" to "Leonardo di Caprio". The function StrConv converts to "Leonardo Di Caprio" and we think it is innapropriated. Any help appreciated. Thank you!
3
3267
by: kronus | last post by:
I'm receiving an xml file that has a child called modified and it represents a date value in the form of a string -- Nov 14, 2008 -- and in my app, I have items associated with each object and I'm trying to sort them by the date modified field. So what's the problem, right? Well, obviously Sep 14, 2008 is before Nov 14, 2008, but when doing...
0
7852
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8216
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8349
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6629
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5719
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3845
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3882
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1455
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1192
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.