473,395 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

parse comma delimited text string

in MS VC++ Express I need to know how to get from one comma delimited
text string to many strings.

from this:

main_string = "onE,Two,Three , fouR,five, six "

to these:

string1 = "one"
string2 = "two"
string3 = "three"
string4 = "four"
string5 = "five"
string6 = "six"

the white space needs to be removed and the case needs to be all upper
or lower.
The result needs to be strings and not pointers or addresses in memory
so I can test:

string test = "three";

if (three == "three")

some getlines will only have two strings some may have up to 10
Please help with examples, you input with exact syntax is greatly
appreciated

I have been struggling with not using pointers but every time I end up
using them.

Thanks in advance

Feb 7 '06 #1
25 31694
electrixnow wrote:
in MS VC++ Express I need to know how to get from one comma delimited
text string to many strings.

from this:

main_string = "onE,Two,Three , fouR,five, six "

to these:

string1 = "one"
string2 = "two"
string3 = "three"
string4 = "four"
string5 = "five"
string6 = "six"
For this, a couple of options are the good old C strtok, or the
std::string find members.
the white space needs to be removed and the case needs to be all upper
or lower.


See toxxxx() and isxxx() functions.

Looks too much like homework to me...

--
Ian Collins.
Feb 7 '06 #2
Howework, not even close. I am an 42 year old EE and not really a
programmer. I have an application at work to apply this to. I am trying
to compare two data files and create a third to let my department know
when new releases for drawing are ready. I have tried strtok, and
strtok_s but those functions allways create pointers. That is fine if I
knew how to easly change them back to STRINGS for string comparison. By
the way we have the same last name, that's wierd.

been out of school for too many years!

The only coding I have done was born, corn and c shell in the 80's. C++
is so much more robust, I am trying to learn more. I just purchased a
book C++ without fear. If you have any suggestions for books for VC++
let me know.

what is the best way to compare text strings like this:

if ( "test string" == pointer_returned_from_strtok )

that will get me going in the right directions.

Thanks!

Feb 7 '06 #3
electrixnow wrote:
Howework, not even close. I am an 42 year old EE and not really a
programmer. I have an application at work to apply this to. I am trying
to compare two data files and create a third to let my department know
when new releases for drawing are ready. I have tried strtok, and
strtok_s but those functions allways create pointers. That is fine if I
knew how to easly change them back to STRINGS for string comparison. By
#include <string>
#include <iostream>

int main() {
// C style string
char mystring[] = "hello world";

// pointer to null terminated token
char* token = mystring + 6;

// create string from token
std::string newString(token);

if (newString == "world") {
std::cout << "Comparison True" << std::endl;
} else {
std::cout << "Comparison Fasle" << std::endl;
}
}
The only coding I have done was born, corn and c shell in the 80's. C++
is so much more robust, I am trying to learn more. I just purchased a
book C++ without fear. If you have any suggestions for books for VC++
let me know.
Accelerated C++, by Koenig and Moo.
what is the best way to compare text strings like this:

if ( "test string" == pointer_returned_from_strtok )
// create string on the fly
if ("test string" == std::string(pointer_returned_from_strtok))
that will get me going in the right directions.


Off you go then! :)

Ben Pope
--
I'm not just a number. To many, I'm known as a string...
Feb 7 '06 #4
* electrixnow:
in MS VC++ Express I need to know how to get from one comma delimited
text string to many strings.

from this:

main_string = "onE,Two,Three , fouR,five, six "

to these:

string1 = "one"
string2 = "two"
string3 = "three"
string4 = "four"
string5 = "five"
string6 = "six"

the white space needs to be removed and the case needs to be all upper
or lower.
The result needs to be strings and not pointers or addresses in memory
so I can test:

string test = "three";

if (three == "three")

some getlines will only have two strings some may have up to 10
Please help with examples, you input with exact syntax is greatly
appreciated

I have been struggling with not using pointers but every time I end up
using them.


std::string uppercase( std::string const& s )
{
std::string result = s;
for( std::size_t i = 0; i < s.length(); ++i )
{
result[i] = static_cast<char>( std::toupper( s[i] ) );
}
return result;
}

typedef std::vector<std::string> StringVector;

StringVector stringsFrom( std::string s )
{
std::replace( s.begin(), s.end(), ',', ' ' );
std::istringstream stream( s );
StringVector result;
for( ;; )
{
std::string word;
if( !( stream >> word ) ) { break; }
result.push_back( uppercase( word ) );
}
return result;
}

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Feb 7 '06 #5

"electrixnow" <info...@charter.net> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
in MS VC++ Express I need to know how to get from one comma delimited
text string to many strings.

from this:

main_string = "onE,Two,Three , fouR,five, six "


You could try something like this:
#include <string>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cctype>
void trim(std::string& str)
{
std::string::size_type idx = str.find_first_not_of(' ');
if (idx != std::string::npos) {
str.erase(0, idx);
}
idx = str.find_last_not_of(' ');
if (idx != std::string::npos) {
str.erase(idx+1, str.size()-1);
}
}

int main()
{
std::string main_string = "onE,Two,Three , fouR,five, six ,,
d, , ";

std::istringstream iss(main_string);
std::string tok;

while (getline(iss, tok, ',')) {
std::transform(tok.begin(), tok.end(), tok.begin(),
std::tolower);
trim(tok);
std::cout << '!' << tok << "!\n";
}
}

Regards,
Sumit.
--
Sumit Rajan <su****@msdc.hcltech.com>
Feb 7 '06 #6

"Sumit Rajan" <su*********@gmail.com> wrote in message
news:44************@individual.net...
void trim(std::string& str)
{
std::string::size_type idx = str.find_first_not_of(' ');
if (idx != std::string::npos) {
str.erase(0, idx);
}
idx = str.find_last_not_of(' ');
if (idx != std::string::npos) {
str.erase(idx+1, str.size()-1);
}
}


Sorry, this function has a bug. May be simplest to use an std::istringstream
as you will see in Alf's post.

Sumit.
--
Sumit Rajan <su****@msdc.hcltech.com>
Feb 7 '06 #7

"Sumit Rajan" <su*********@gmail.com> wrote in message
news:44************@individual.net...
void trim(std::string& str)
{
std::string::size_type idx = str.find_first_not_of(' ');
if (idx != std::string::npos) {
str.erase(0, idx);
}
idx = str.find_last_not_of(' ');
if (idx != std::string::npos) {
str.erase(idx+1, str.size()-1);
}
}


void trim(std::string& str)
{
while((!str.empty()) && isspace(str[0])) {
str.erase(0, 1);
}
std::string::size_type idx = str.find_last_not_of(' ');
if (!((idx == std::string::npos)||(idx == str[str.size()-1]))) {
str.erase(idx+1, str.size()-1);
}
}

Regards,
Sumit.
--
Sumit Rajan <su****@msdc.hcltech.com>
Feb 7 '06 #8
In article <11*********************@g47g2000cwa.googlegroups. com>,
"electrixnow" <info...@charter.net> wrote:
in MS VC++ Express I need to know how to get from one comma delimited
text string to many strings.

from this:

main_string = "onE,Two,Three , fouR,five, six "

to these:

string1 = "one"
string2 = "two"
string3 = "three"
string4 = "four"
string5 = "five"
string6 = "six"

the white space needs to be removed and the case needs to be all upper
or lower.
The result needs to be strings and not pointers or addresses in memory
so I can test:

string test = "three";

if (three == "three")

some getlines will only have two strings some may have up to 10
Please help with examples, you input with exact syntax is greatly
appreciated

I have been struggling with not using pointers but every time I end up
using them.

Thanks in advance


Assuming there are no spaces other than the ones just before or just
after the commas, the following will work:

template < typename Out >
void fn( string str, Out it )
{
int (*lower)(int) = &tolower;
transform( str.begin(), str.end(), str.begin(), lower );
replace( str.begin(), str.end(), ',', ' ' );
stringstream ss( str );
copy( istream_iterator<string>( ss ), istream_iterator<string>(),
it );
}

Call the above with a container that has the space or using a
back_inserter. For example:

vector<string> vec;
fn( main_string, back_inserter( vec ) );

The only magic is replacing the comma's with spaces so that the
stringstream will ignore them.
If there are spaces that must be saved then the above won't work. For
example:

main_string = "John Smith, Mark Allen ,Joe";

If the above needs to be parsed to:
vec[0] = "john smith"
vec[1] = "mark allen"
vec[2] = "joe"

Here we can't just dump the commas...

// returns a string that has had the whitespace at the front
// and back removed without disturbing the whitespace in the middle
string strip( string str )
{
const char* const whitespace = " \t";
str.erase( 0, str.find_first_not_of( whitespace ) );
string::size_type pos = str.find_last_not_of( whitespace );
if ( pos != string::npos )
str.erase( pos + 1 );
return str;
}

template < typename Out >
void foo( string str, Out it )
{
int (*lower)(int) = &tolower;
transform( str.begin(), str.end(), str.begin(), lower );
string::size_type prev = 0;
for ( string::size_type pos = str.find( ',' ); pos != string::npos;
pos = str.find( ',', prev ) )
{
string s = strip( str.substr( prev, pos - prev ) );
it++ = s;
prev = pos + 1;
}
string s = strip( str.substr( prev ) );
it = s;
}

--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
Feb 7 '06 #9
In article <po******************************@news.east.earthl ink.net>,
"Daniel T." <po********@earthlink.net> wrote:
If there are spaces that must be saved then the above won't work. For
example:

main_string = "John Smith, Mark Allen ,Joe";

If the above needs to be parsed to:
vec[0] = "john smith"
vec[1] = "mark allen"
vec[2] = "joe"

Here we can't just dump the commas...

// returns a string that has had the whitespace at the front
// and back removed without disturbing the whitespace in the middle
string strip( string str )
{
const char* const whitespace = " \t";
str.erase( 0, str.find_first_not_of( whitespace ) );
string::size_type pos = str.find_last_not_of( whitespace );
if ( pos != string::npos )
str.erase( pos + 1 );
return str;
}

template < typename Out >
void foo( string str, Out it )
{
int (*lower)(int) = &tolower;
transform( str.begin(), str.end(), str.begin(), lower );
string::size_type prev = 0;
for ( string::size_type pos = str.find( ',' ); pos != string::npos;
pos = str.find( ',', prev ) )
{
string s = strip( str.substr( prev, pos - prev ) );
it++ = s;
prev = pos + 1;
}
string s = strip( str.substr( prev ) );
it = s;
}


I liked Sumit Rajan's use of getline... Modified my code to use it.

string& strip( string& str )
{
const char* const whitespace = " \t";
str.erase( 0, str.find_first_not_of( whitespace ) );
string::size_type pos = str.find_last_not_of( whitespace );
if ( pos != string::npos )
str.erase( pos + 1 );
return str;
}

template < typename Out >
void fn( string str, Out it )
{
int (*lower)(int) = &tolower;
transform( str.begin(), str.end(), str.begin(), lower );
stringstream ss( str );
string s;
while ( getline( ss, s, ',' ) )
it++ = strip( s );
}
--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
Feb 7 '06 #10
In article <44************@individual.net>,
"Sumit Rajan" <su*********@gmail.com> wrote:
"Sumit Rajan" <su*********@gmail.com> wrote in message
news:44************@individual.net...
void trim(std::string& str)
{
std::string::size_type idx = str.find_first_not_of(' ');
if (idx != std::string::npos) {
str.erase(0, idx);
}
idx = str.find_last_not_of(' ');
if (idx != std::string::npos) {
str.erase(idx+1, str.size()-1);
}
}


Sorry, this function has a bug. May be simplest to use an std::istringstream
as you will see in Alf's post.


What bug do you see? The only bug I can find is that if 'str' is nothing
but spaces then the function doesn't do anything.

--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
Feb 7 '06 #11
Since your using VC++ express, are you using standard C++ or C++/CLI?
I ask becasue if your using the managed String classes, you can very
easily do what you wish as follows:

System::String^ s = "1,2,3,4,5";
cli::array<System::String^>^ s2 = s->Split(',');
// now use s2[0]...s2[s2->Length] as needed.

If using standard C++, then the suggestions already provided by the
other posters are worth considering.

Feb 7 '06 #12
On Tue, 07 Feb 2006 11:05:54 GMT, al***@start.no (Alf P. Steinbach)
wrote:
StringVector stringsFrom( std::string s )
{
std::replace( s.begin(), s.end(), ',', ' ' );
std::istringstream stream( s );
StringVector result;
for( ;; )
{
std::string word;
if( !( stream >> word ) ) { break; }
result.push_back( uppercase( word ) );
}
return result;
}


Alternative string tokenizers can be found here:
http://groups.google.com/group/comp....8f07f527?hl=en

Best regards,
Roland Pibinger
Feb 7 '06 #13
electrixnow wrote:
the white space needs to be removed and the case needs to be all upper
or lower.


My favorite approach would be to use a filtering stream buffer
to do the clean-up and use normal string input functions otherwise:

#include <iostream>
#include <streambuf>
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>
#include <stdlib.h>

char clean(char i)
{
return i == ','? ' '
: std::tolower(static_cast<unsigned char>(i));
}

struct cleanbuf:
std::streambuf
{
enum { s_size = 1024 };
cleanbuf(std::streambuf* sbuf): m_sbuf(sbuf) {}
int underflow()
{
std::streamsize size = m_sbuf->sgetn(m_buf, s_size);
setg(m_buf, m_buf, m_buf + size);
std::transform(m_buf + 0, m_buf + size, m_buf, clean);
return gptr() == egptr()
? std::char_traits<char>::eof(): *gptr();
}
private:
std::streambuf* m_sbuf;
char m_buf[s_size];
};

int main()
{
cleanbuf sbuf(std::cin.rdbuf());
std::istream in(&sbuf);
std::vector<std::string> strs(
(std::istream_iterator<std::string>(in)),
(std::istream_iterator<std::string>()));
std::copy(strs.begin(), strs.end(),
std::ostream_iterator<std::string>(std::cout, "\n"));
}
~
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.eai-systems.com> - Efficient Artificial Intelligence
Feb 8 '06 #14

"Daniel T." <po********@earthlink.net> wrote in message
news:po******************************@news.east.ea rthlink.net...
What bug do you see? The only bug I can find is that if 'str' is nothing
but spaces then the function doesn't do anything.


Precisely. My other post on this thread takes care of it.

Regards,
Sumit.
--
Sumit Rajan <su****@msdc.hcltech.com>
Feb 8 '06 #15
In article <44************@individual.net>,
"Sumit Rajan" <su*********@gmail.com> wrote:
"Daniel T." <po********@earthlink.net> wrote in message
news:po******************************@news.east.ea rthlink.net...
What bug do you see? The only bug I can find is that if 'str' is nothing
but spaces then the function doesn't do anything.


Precisely. My other post on this thread takes care of it.


I think your other post was more complicated than necessary...

str.erase( 0, str.find_first_not_of( whitespace ) );

Takes care if it without the extra conditionals/loops.

--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
Feb 8 '06 #16
In article <44************@individual.net>,
Dietmar Kuehl <di***********@yahoo.com> wrote:
electrixnow wrote:
the white space needs to be removed and the case needs to be all upper
or lower.
My favorite approach would be to use a filtering stream buffer
to do the clean-up and use normal string input functions otherwise:


Unfortunately, your code doesn't compile on my system. I had to change
the vector<string> c_tor call to:

vector<string> strs;
copy ( istream_iterator<string>(in), istream_iterator<string>(),
back_inserter(strs) );

Also, your code only works for the simple case, where there is no
whitespace *within* a string delimited by commas. How would you change
it to account for the more complicated case?

The nice thing about your code is that it does everything in a single
pass whereas the code I presented to date requires two passes (one to
call tolower, and a second to remove the commas.) It would be a simple
change to make mine one pass as well...

template < typename Out >
void fn( string str, Out it )
{
transform( str.begin(), str.end(), str.begin(), clean );
// the above uses your 'clean' function.
stringstream ss( str );
copy( istream_iterator<string>( ss ), istream_iterator<string>(),
it );
}

This seems much more straight forward and needs fewer lines of code.

I must say that every contribution so far has shed new light on the
problem for me and caused me to improve my code in some way. IMHO, this
is usenet at its best.
#include <iostream>
#include <streambuf>
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>
#include <stdlib.h>

char clean(char i)
{
return i == ','? ' '
: std::tolower(static_cast<unsigned char>(i));
}

struct cleanbuf:
std::streambuf
{
enum { s_size = 1024 };
cleanbuf(std::streambuf* sbuf): m_sbuf(sbuf) {}
int underflow()
{
std::streamsize size = m_sbuf->sgetn(m_buf, s_size);
setg(m_buf, m_buf, m_buf + size);
std::transform(m_buf + 0, m_buf + size, m_buf, clean);
return gptr() == egptr()
? std::char_traits<char>::eof(): *gptr();
}
private:
std::streambuf* m_sbuf;
char m_buf[s_size];
};

int main()
{
cleanbuf sbuf(std::cin.rdbuf());
std::istream in(&sbuf);
std::vector<std::string> strs(
(std::istream_iterator<std::string>(in)),
(std::istream_iterator<std::string>()));
std::copy(strs.begin(), strs.end(),
std::ostream_iterator<std::string>(std::cout, "\n"));
}
~


--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
Feb 8 '06 #17

"Daniel T." <po********@earthlink.net> wrote in message
news:po******************************@news.east.ea rthlink.net...
I think your other post was more complicated than necessary...

str.erase( 0, str.find_first_not_of( whitespace ) );

Takes care if it without the extra conditionals/loops.


True. This one is far more reader-friendly.

Regards,
Sumit.
--
Sumit Rajan <su****@msdc.hcltech.com>
Feb 8 '06 #18
Daniel T. wrote:
Unfortunately, your code doesn't compile on my system. I had to change
the vector<string> c_tor call to:

vector<string> strs;
copy ( istream_iterator<string>(in), istream_iterator<string>(),
back_inserter(strs) );
In this case your compiler or the standard library implementation is
broken: the standard container classes are defined to accept pairs of
input iterators as constructor arguments.
Also, your code only works for the simple case, where there is no
whitespace *within* a string delimited by commas. How would you change
it to account for the more complicated case?
This is a rather different specification which, in particular, does
not yet account for whitespace at the beginning or the end of the
string: is this whitespace to be removed or not? Since commas work
as true delimiters here, I assume it is to be included. I this case
I would [temporarily] 'imbue()' a 'std::ctype<char>' facet which
only considers comma and possibly newline (if this is also considered
a separator). The extractor functions use whitespaces as field
separators for strings. If the case adjustment is still necessary,
I would use the modified facet in combination with the filtering
stream buffer.
This seems much more straight forward and needs fewer lines of code.
Injecting existing filtering stream buffers into the processing is
pretty straight forward. Of course, writing them is not necessarily
so but it is not that hard either. The real advantage I see in the
filtering stream buffer over your code is that it encapsulates the
complete solution, especially if it is also equipped with a simple
input stream which automatically maintains the stream buffer.
I must say that every contribution so far has shed new light on the
problem for me and caused me to improve my code in some way.


This was my intention of posting the code...
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.eai-systems.com> - Efficient Artificial Intelligence
Feb 8 '06 #19
Daniel T. wrote:
int (*lower)(int) = &tolower;
transform( str.begin(), str.end(), str.begin(), lower );


Note that this does *NOT* work! The argument to 'std::tolower()'
has to be an *unsigned* value. However, on platforms where 'char'
is signed, the argument could expand to a negative value! In
portable code, the only valid call to 'std::tolower(int)' with a
'char' looks like this:

std::tolower(static_cast<unsigned char>(c));

The only possible variation is how the 'char' is first cast to
an 'unsigned char'.
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.eai-systems.com> - Efficient Artificial Intelligence
Feb 8 '06 #20
Alf P. Steinbach wrote:
result[i] = static_cast<char>( std::toupper( s[i] ) );


The above line shall read

result[i] = std::toupper( static_cast<unsigned char>(s[i]));

While the compiler automatically takes care of the conversion from
'char' to 'int', it could produce negative values on systems where
'char' is a signed type without the explicit conversion to 'unsigned
char'. However, 'std::toupper(int)' only accepts positive values
making it necessary to convert the 'char' to an 'unsigned char'
first.
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.eai-systems.com> - Efficient Artificial Intelligence
Feb 8 '06 #21
In article <44************@individual.net>,
Dietmar Kuehl <di***********@yahoo.com> wrote:
Daniel T. wrote:
int (*lower)(int) = &tolower;
transform( str.begin(), str.end(), str.begin(), lower );


Note that this does *NOT* work! The argument to 'std::tolower()'
has to be an *unsigned* value. However, on platforms where 'char'
is signed, the argument could expand to a negative value! In
portable code, the only valid call to 'std::tolower(int)' with a
'char' looks like this:

std::tolower(static_cast<unsigned char>(c));

The only possible variation is how the 'char' is first cast to
an 'unsigned char'.


That is only necessary if one is using an extended character set. For
all ASCII characters, "tolower( c )" will work just fine. In order to
write portable code, one must not use an extended character set, making
the cast will not magically make it portable.

--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
Feb 8 '06 #22
In article <44************@individual.net>,
Dietmar Kuehl <di***********@yahoo.com> wrote:
Injecting existing filtering stream buffers into the processing is
pretty straight forward. Of course, writing them is not necessarily
so but it is not that hard either. The real advantage I see in the
filtering stream buffer over your code is that it encapsulates the
complete solution, especially if it is also equipped with a simple
input stream which automatically maintains the stream buffer.


I read up on streambuf's last night. Although, your solution does work,
I think it is inappropriate. Stream Buffers are supposed to represent
buffering strategies for different kinds of streams, not conversion
strategies.

Both of our codes encapsulated the complete solution.
--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
Feb 8 '06 #23
Daniel T. wrote:
I read up on streambuf's last night.
Just out if interest: where did you read up on them?
Although, your solution does work,
I think it is inappropriate. Stream Buffers are supposed to represent
buffering strategies for different kinds of streams, not conversion
strategies.
Stream buffers are intended to represent streams of characters.
When streaming characters, it is quite common to transform them
in some way. Actually, this is the basis of UNIX' approach to
filters. My code effectively just did the moral equivalent of
"tr 'A-Z,' 'a-z '" which is, IMO, an entirely appropriate use
of streams.

In fact, even at the very basis of file streams, (i.e. in the
class template 'std::basic_filebuf') a heavy conversion mechanism
is employed which converts bytes read from a file into characters
used within an application or vice versa. This uses 'std::codecvt'
facets and it would be an easy typing exercise to inject the
conversion I implemented in the stream buffer into a corresponding
facet.
Both of our codes encapsulated the complete solution.


Well, I somewhat disagree with this statement but then, the
problem was trivial enough that it may not be worth to encapsulate
the solution further than you did.
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.eai-systems.com> - Efficient Artificial Intelligence
Feb 8 '06 #24
Daniel T. wrote:
That is only necessary if one is using an extended character set. For
all ASCII characters, "tolower( c )" will work just fine. In order to
write portable code, one must not use an extended character set, making
the cast will not magically make it portable.


As far as I know, standard C++ does not privilege the ascii charset in any
way, nor any other 0-127 charset.

Of course you have less problems if you know for sure that all your users
use ascii. But you will also have less users.

--
Salu2
Feb 8 '06 #25
* Dietmar Kuehl:
Alf P. Steinbach wrote:
result[i] = static_cast<char>( std::toupper( s[i] ) );
The above line shall read

result[i] = std::toupper( static_cast<unsigned char>(s[i]));


Thanks for that correction, it was a screw-up.

While the compiler automatically takes care of the conversion from
'char' to 'int', it could produce negative values on systems where
'char' is a signed type without the explicit conversion to 'unsigned
char'. However, 'std::toupper(int)' only accepts positive values
And EOF. ;-)

making it necessary to convert the 'char' to an 'unsigned char'
first.


--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Feb 8 '06 #26

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

Similar topics

4
by: Arne | last post by:
From: "Arne de Booij" <a_de_booij@hotmail.com> Subject: Comma delimited array into DB problems Date: 9. februar 2004 10:39 Hi, I have an asp page that takes input from a form on the previous...
18
by: MW | last post by:
Dear All Does anyone have a regular expression to parse a comma delimited line with some fields optionally having string delimiters (text qualifiers) I am currently testing with this regular...
22
by: Ram Laxman | last post by:
Hi all, I have a text file which have data in CSV format. "empno","phonenumber","wardnumber" 12345,2234353,1000202 12326,2243653,1000098 Iam a beginner of C/C++ programming. I don't know how to...
2
by: Larry Williams | last post by:
Is there an easy way to convert a string of data to XML format without having to create the xml one field at a time? Sorry I'm a newbie and my xml knowledge is limited. I have tried to search...
9
by: Wayne | last post by:
I have the following string: "smith", "Joe", "West Palm Beach, Fl." I need to split this string based on the commas, but as you see the city state contains a comma. String.split will spilt the...
5
by: Yama | last post by:
Hi, I am looking to create a report comma delimited on a click of a button. Explanantion: 1. Get from the database: "SELECT * FROM Customers WHERE Region = 'CA'" 2. Use either DataReader or...
2
by: Ron | last post by:
so if my textbox is named textbox1 and my listbox is named ltsdisplay, for the button that would make this all happen I would just need to: ...
5
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C++ programming. FYI Although I have called...
1
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C programming. FYI Although I have called this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.