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

checking for printable characters

How do you check whether an std::string object contains only printable characters ?
Jul 19 '05 #1
2 8840
"qazmlp" <qa********@rediffmail.com> wrote in message
news:db*************************@posting.google.co m...
How do you check whether an std::string object contains only printable
characters ?


I think this would work:

#include <algorithm>
#include <cctype>
#include <functional>
#include <string>

namespace util
{
bool isAllPrintable (std::string const &s)
{
typedef std::unary_negate<
std::pointer_to_unary_function<int, int> > NotFunc;
NotFunc isNotPrintable(std::ptr_fun(std::isprint));
return std::find_if(s.begin(), s.end(), isNotPrintable) ==
s.end();
}
}

--
Russell Hanneken
rh*******@pobox.com
Jul 19 '05 #2

"qazmlp" <qa********@rediffmail.com> wrote in message
news:db*************************@posting.google.co m...
How do you check whether an std::string object contains only printable

characters ?

bool printable = true;
for (string::const_iterator i = s.begin(); i != s.end(); ++i)
{
if (!isprint(*i))
{
printable = false;
break;
}
}

Why anyone would prefer using something from <algorithm> beats me, but each
to his own.

john
Jul 19 '05 #3

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

Similar topics

2
by: Jim | last post by:
Hi, Does anyone know of an available java class that will encrypt to cipher text consisting of only printable ascii characters? One of the things I need it for is to encrypt strings that will...
3
by: Pascal | last post by:
Hello, What's the best way to delete or replace no-printable characters in a string. i.e.: "\x08toto\x00titi" -> "tototiti" or " toto titi"
2
by: Daniel Alexandre | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi there, I'm using the following method in my program to check whether a message received is printable or not and to strip the non-printable...
0
by: qazmlp | last post by:
How do you check whether an std::string object contains only printable characters ?
5
by: **Developer** | last post by:
How do I know if the value in a KeyEventArgs is printable? Basicacally, in KeyUp I'd like to know if the character is printable, as opposed to say, a backspace. I suppose I could check...
0
by: ramarajs | last post by:
Hi Team, Can anyone give me the regular expression to search the following set of non printable characters ÑÑNL, &quot; ˜ and many more non printable characters. I have to search these characters...
7
by: active | last post by:
I want to remove all non-printable characters - including nulls. I could extend the following by adding as many printable characters as I can think of. But I wonder if there isn't something...
4
by: John K Masters | last post by:
>From what I have read the string module is obsolete and should not be used but I am working on a project that parses printable files created in a DOS program and creates a web page for each file....
3
by: =?Utf-8?B?R3JleWhvdW5k?= | last post by:
I need to remove non-printable characters from a text file. I need to do this in C#. The Hex codes for the characters I need to remove are '0C' and '0A' which equate to 12 and 10 in decimal. ...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...

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.