Greetings,
Is there an easy way to remove multiple non-printable
(e.g. "not strings.printab le") from a string? Perhaps
something like foo.replace(lis t_of_nonprintab les, '')
if it only existed? :-)
Cheers,
don 3 10569
"Don Hiatt" <do******@acm.o rg> wrote in message
news:2b******** *************** ***@posting.goo gle.com... Is there an easy way to remove multiple non-printable (e.g. "not strings.printab le") from a string? Perhaps something like foo.replace(lis t_of_nonprintab les, '') if it only existed? :-) help(str.transl ate)
translate(...)
S.translate(tab le [,deletechars]) -> string
Return a copy of the string S, where all characters occurring
in the optional argument deletechars are removed, and the
remaining characters have been mapped through the given
translation table, which must be a string of length 256.
s_identity=''.j oin([chr(i) for i in range(256)]) # the 'table' you
need
Terry J. Reedy
This seems to work. Not sure how fast it'd be, though.
def stripNoPrint(st r):
results = ""
for char in str:
if string.printabl e.find(char):
results += char
return results
Don Hiatt wrote: Greetings,
Is there an easy way to remove multiple non-printable (e.g. "not strings.printab le") from a string? Perhaps something like foo.replace(lis t_of_nonprintab les, '') if it only existed? :-)
Cheers,
don
Don> Is there an easy way to remove multiple non-printable (e.g. "not
Don> strings.printab le") from a string? Perhaps something like
Don> foo.replace(lis t_of_nonprintab les, '') if it only existed? :-)
Check out the string module's translate function.
Skip This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Anita |
last post by:
Hi All
I have a table with one column :
CREATE TABLE test2
( a char(15)
primary KEY CLUSTERED )
The column a is filled with encrypted data
(contains control and extended characters).
|
by: Durgesh Sharma |
last post by:
Hi All,
Pleas help me .I am a starter as far as C Language is concerned .
How can i Right Trim all the white spaces of a very long (2000 chars)
Charecter string ( from the Right Side ) ? or how can i make a fast
Right Trim Function in c,using Binary search kind of fast algorithm ?
Offcourse...I can use the classical approach too.
like :
Start from the right most charecter of the string to the left of the
|
by: hoggmeister |
last post by:
Hi,
Im new to C coming from a java background. I having difficulty
adjusting to C and was hoping someone could help me with a little
simple code to get started. I would like a little program that outputs
on to the console a message like "please enter some text" then when the
user enters text it gets stored in a char array or whatever is best. I
then want to check that the array is no longer than 25 chars ( i dont
know if malloc is...
|
by: Jason Shohet |
last post by:
I'm getting a URL w/ a querystring coming in to start my app.
In session_start, I was thinking of scrambling that querystring to keep it
from prying eyes....
Any ideas?
Doesn't need to be fullproof, just quick and dirty :) ty jason shohet
|
by: kbarz |
last post by:
Hi,
I have a VB.Net program that extracts data from Word document tables and saves it off to Sql Server. I notice that when it gets to the database, there are two nonprintable characters on the end of each field. I thought of using substring-before to parse these out, but I'm not sure how to refer to them as they are just represented as squares in the database. I'd also like to convert number strings to numerics but need to get rid of...
| |
by: guy |
last post by:
if a string contains surrogate chars (i.e. Unicode characters that consiste
of more than 1 char) do functions that use an indexer or a string length into
the string e.g. Mid, Len work correctly?
guy
|
by: Mike Copeland |
last post by:
I have data I need to normalize - it's "name" data. For example, I
have the following: "Watts, J.C." I wish to (1) parse the "first name"
("J.C.") and adjust it to "JC". Essentially, I want to remove the
punctuation characters from the "first name" substring.
I've looked at the basic_string in C++, but I can't find the
functions that will _remove" character(s) from a value. There are
operators that are helpful in finding the position...
|
by: Brad |
last post by:
I'm writing a function to remove certain characters from strings. For
example, I often get strings with commas... they look like this:
"12,384"
I'd like to take that string, remove the comma and return "12384"
What is the most efficient, fastest way to approach this?
Thanks,
|
by: imLVcrazy |
last post by:
Hi
Does any1 know of a method where you can search through a string and remove chars from a specific pointer until the new line. For example:
"This is a test @ A test this is"
how do make it so u search for a pointer (e.g.@) and make it this:
"This is a test"
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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,...
| |
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...
|
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...
|
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();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
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...
| |