473,396 Members | 1,972 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,396 software developers and data experts.

how to check a string whether it is

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

Mar 14 '06 #1
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 );
Mar 14 '06 #2
thanks
I mean how to judge a string whether there is no any other character
besides backspace,\t,and \n

Mar 14 '06 #3
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
Mar 14 '06 #4
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
Mar 14 '06 #6
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;
}
}
}
Mar 14 '06 #7
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
Mar 14 '06 #8
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...
Mar 14 '06 #9
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
Mar 14 '06 #10

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

Similar topics

27
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...
6
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",...
10
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? ...
35
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
6
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...
2
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',...
3
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!
3
Maidenz08
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...
55
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...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
marktang
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,...
0
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...
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
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.