how to check a string whether it is

Z

zjffdu

I know in .net it is easy, but in C++
how can I check a string whether it is composed by backspace,\t,\n?
Is there function can i call in the standard?

thanks for any hint
 
J

Jim Langston

zjffdu said:
I know in .net it is easy, but in C++
how can I check a string whether it is composed by backspace,\t,\n?
Is there function can i call in the standard?

thanks for any hint

Not exactly sure what you're asking for. But std::string.find_first_of()
might be what you want. "Whether it is composed by..." Is it totally? Or
included? Totally would be a simple == as in if ( MyString == "\t" ) has
within you could use if ( MyString.find_first_of("\t") != std::npos );
 
Z

zjffdu

thanks
I mean how to judge a string whether there is no any other character
besides backspace,\t,and \n
 
D

Dietmar Kuehl

zjffdu said:
I mean how to judge a string whether there is no any other character
besides backspace,\t,and \n

if (str.find_first_not_of("\t\n\b") == str.npos)
std::cout << "the string contains nothing interesting\n";
 
T

Tomás

zjffdu posted:
I know in .net it is easy, but in C++
how can I check a string whether it is composed by backspace,\t,\n?
Is there function can i call in the standard?

thanks for any hint

Here's an elementary way to test if either character is present:

bool EitherPresent( const char* p )
{
for( ; ; ++p )
{
switch ( *p )
{
case '\t':
case '\n':
{
return true;
}

case 0:
{
return false;
}
}
}
}


-Tomás
 
T

Tomás

zjffdu posted:
thanks
I mean how to judge a string whether there is no any other character
besides backspace,\t,and \n

Simple again.

bool AnythingIntelligible( const char* p )
{
for( ; ; ++p )
{
switch ( *p )
{
case '\t':
case '\n':

break;

case 0:
{
return false;
}

default:

return true;
}
}
}
 
?

=?ISO-8859-15?Q?Juli=E1n?= Albo

Dietmar said:
if (str.find_first_not_of("\t\n\b") == str.npos)
std::cout << "the string contains nothing interesting\n";

If the string contains a program in the whitespace language, it can be very
interesting.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top