473,767 Members | 7,225 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

checking for printable characters

How do you check whether an std::string object contains only printable characters ?
Jul 19 '05 #1
2 8872
"qazmlp" <qa********@red iffmail.com> wrote in message
news:db******** *************** **@posting.goog le.com...
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_nega te<
std::pointer_to _unary_function <int, int> > NotFunc;
NotFunc isNotPrintable( std::ptr_fun(st d::isprint));
return std::find_if(s. begin(), s.end(), isNotPrintable) ==
s.end();
}
}

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

"qazmlp" <qa********@red iffmail.com> wrote in message
news:db******** *************** **@posting.goog le.com...
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
5361
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 then be used as filenames. TIA, Jim
3
2492
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
5476
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 characters: CheckPrintable(self,message): printablemessage = ""
0
651
by: qazmlp | last post by:
How do you check whether an std::string object contains only printable characters ?
5
3295
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 KeyValue against some integers which I could get from an ASCII table. Isn't there a better way?
0
3106
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 and remove the same from the file. I need the regular expression to find the combination of above said characters. Any inputs on the same would be appreciated. Thanks in advance. Thank you, Ramaraj. S
7
34642
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 better. Like a \something that does it all? Return Regex.Replace(oStr, "", "").Trim
4
2525
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. I am using the string.printable constant to determine which characters should be kept; the files contain many print control codes. There seems to be nothing like this in the string methods. isalnum() seems the nearest but gives false for '+' '!'...
3
17104
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. Their codes are 'FF' and 'LF' from the ASCII talbe. I have searched and searched and cannot come up with a method for doing this. Many Thanks...
0
9575
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10171
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9960
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9842
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8840
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7384
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6656
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5425
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2808
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.