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 9 1905
"zjffdu" <zj****@gmail.com> wrote in message
news:11*********************@i40g2000cwc.googlegro ups.com... 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 );
thanks
I mean how to judge a string whether there is no any other character
besides backspace,\t,and \n
zjffdu wrote: 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";
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.eai-systems.com> - Efficient Artificial Intelligence
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
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;
}
}
}
Diego Martins wrote: http://www.cppreference.com/cppstring/index.html
Er, I think I know the standard C++ library quite well. Did I goof?
.... and, if so, where?
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.eai-systems.com> - Efficient Artificial Intelligence
Diego Martins wrote: http://www.cppreference.com/cppstring/index.html
Do you have a point?
I'm pretty sure you're not just randomly pasting links into messages but
it would be good to quote some context from the post to which you are
responding, and also adding some words to describe the point of
providing the link.
Ben Pope
--
I'm not just a number. To many, I'm known as a string...
Dietmar Kuehl wrote: 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.
--
Salu2 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: John Roth |
last post by:
PEP 263 is marked finished in the PEP index, however
I haven't seen the specified Phase 2 in the list of changes
for 2.4 which is when I expected it.
Did phase 2 get cancelled, or is it just not...
|
by: Jan |
last post by:
Hi,
Is there any elegant way in VB.NET to check whether a certain string is part
of a "collection" of strings.
Something like IF "teststring" in {"string1", "string2", "string3",...
|
by: kd |
last post by:
Hi All,
Is there a command to check whether a given string is present in a text
file, without having to read the contents of the file, a line at a time and
then check for the given string?
...
|
by: pinkfloydhomer |
last post by:
How do I check if a string contains (can be converted to) an int? I
want to do one thing if I am parsing and integer, and another if not.
/David
|
by: tommaso.gastaldi |
last post by:
Hi,
does anybody know a speedy analog of IsNumeric() to check for
strings/chars. I would like to check if an Object can be treated as a
string before using a Cstr(), clearly avoiding the time...
|
by: NEMA |
last post by:
How can i check the String letters?
i have a textbox and will filled with numbers.
i want to check if the number contain a '0' in font of the numbers,
e.g. '090',i would like to cut the 1st '0',...
|
by: SoFaraway |
last post by:
Dear all,
In C, how do we check whether a string starts with a substring? E.g.,
char *str = ...;
char *substr = ...;
How do we check whether str starts with substr?
Thank you very much!
|
by: Maidenz08 |
last post by:
How do i check whether an email id exists or not?
I am following a three step validation process..
1) syntax validation- which is pretty straight forward
2) DNS validation - I'm able to do...
|
by: lovecreatesbea... |
last post by:
Do you check all error conditions for all library calls in you code?
Is it necessary to check all errors? Is it convenient to check all
errors (or how to make code clean and readable with mass of...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
|
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...
|
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...
|
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,...
| |