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 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
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.
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
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;
}
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 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?
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
> > 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
|
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;
|
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...
|
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"
|
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()
| |
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)
|
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++) {
|
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:
|
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!
|
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...
|
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...
| |
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. ...
|
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |