Cédric Lucantis wrote:
I don't see any string method to do that
>>'abcde'.trans late(str.maketr ans('','','bcd' ))
'ae'
I do not claim this to be better than all the other methods,
but this pair can also translate while deleting, which others cannot. 4 2491
Terry Reedy wrote:
Cédric Lucantis wrote:
>I don't see any string method to do that
>>'abcde'.trans late(str.maketr ans('','','bcd' ))
'ae'
I do not claim this to be better than all the other methods,
but this pair can also translate while deleting, which others cannot.
You should mention that you are using Python 3.0 ;)
The 2.5 equivalent would be
>>u"abcde".tran slate(dict.from keys(map(ord, u"bcd")))
u'ae'
Peter
In article <g3************ *@news.t-online.com>,
Peter Otten <__*******@web. dewrote:
>Terry Reedy wrote:
> >>'abcde'.trans late(str.maketr ans('','','bcd' ))
'ae'
You should mention that you are using Python 3.0 ;) The 2.5 equivalent would be
>>>u"abcde".tra nslate(dict.fro mkeys(map(ord, u"bcd")))
u'ae'
Only if you're using Unicode:
>>'abcde'.trans late(string.mak etrans('',''), 'bcd')
'ae'
>>sys.version_i nfo
(2, 4, 4, 'final', 0)
--
\S -- si***@chiark.gr eenend.org.uk -- http://www.chaos.org.uk/~sion/
"Frankly I have no feelings towards penguins one way or the other"
-- Arthur C. Clarke
her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
Sion Arrowsmith wrote:
In article <g3************ *@news.t-online.com>,
Peter Otten <__*******@web. dewrote:
>>Terry Reedy wrote:
>> >>'abcde'.trans late(str.maketr ans('','','bcd' )) 'ae'
You should mention that you are using Python 3.0 ;) The 2.5 equivalent would be
>>>>u"abcde".tr anslate(dict.fr omkeys(map(ord, u"bcd")))
u'ae'
Only if you're using Unicode:
.... which is what you do if you are using the str type in 3.0.
Peter
Peter Otten wrote:
Terry Reedy wrote:
>Cédric Lucantis wrote:
>>I don't see any string method to do that 'abcde'.trans late(str.maketr ans('','','bcd' ))
'ae'
I do not claim this to be better than all the other methods, but this pair can also translate while deleting, which others cannot.
You should mention that you are using Python 3.0 ;)
The 2.5 equivalent would be
>>>u"abcde".tra nslate(dict.fro mkeys(map(ord, u"bcd")))
u'ae'
Sorry. I did not realize that the maketrans function had not then been
moved from the string module to the str class object, unlike nearly all
other functions from string, including the translate function. I also
misremembered that maketrans did not have the new third delete param.
What I did do once long ago was something like
>>import string a = 'abcde'.transla te(string.maket rans('bd','**') ) a.replace('*' ,'')
'ace'
which is not very nice.
tjr This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Marcio Kleemann |
last post by:
I need to force the first letter of each word in a line of text to
uppercase. The text comes from a TextBox control in a Web Form. I'm new to
..NET and am having a problem.
Since I can't modify the string directly, I convert the string to a char
using .ToCharArray() and set the first letter of each word to uppercase. The
problem then is I...
|
by: William Stacey [MVP] |
last post by:
Had a method that got some string info from mp3 tags in N files and
serializes this class and deserializes at other side. Works ok except
sometimes get chars that choke the XmlSerializer. After some digging, I
found XmlSerializer chokes on 0x03 chars. It probably chokes on many
others, but this one I found. It serializes ok, but chokes on...
|
by: Nikolay Petrov |
last post by:
I need a way to strip chars from a string. The chars are all chars that are
not allowed in file path.
TIA
|
by: orangeDinosaur |
last post by:
Hello,
I am encountering a behavior I can think of reason for. Sometimes,
when I use the .strip module for strings, it takes away more than what
I've specified. For example:
>>> a = ' <TD WIDTH=175><FONT SIZE=2>Hughes. John</FONT></TD>\r\n'
>>> a.strip(' <TD WIDTH=175><FONT SIZE=2>')
|
by: Niklas Engfelt |
last post by:
Does anyone have a nice algorithm/method to increase all digits one
step, e.g. 123123 to 234234 and 4444 to 5555 and 999999 to 000000?
Best regards
Niklas
| |
by: sklett |
last post by:
I need to take a string, make the first character lowercase and prepend an
underscore character to it. Something like this:
"California"
"_california"
Here is the (ugly) solution I cam up with:
public static string MakeNetSuiteStateName(string normalStateName)
{
string firstChar = normalStateName.Substring(0, 1);
|
by: Mosquito Man |
last post by:
string s("0101");
I can't change it into s=1101
by
s='1';
because string.this is read-only, no assignment is allowed :-(
thank you for your help
|
by: tcomer |
last post by:
Hello. I'm working on a client/server application and I'm having some
weird issues with concatenating strings. The client program sends some
text:
Object objData = "IssuedCommand:SenderName";
byte byData =
System.Text.Encoding.ASCII.GetBytes(objData.ToString());
if (m_clientSocket != null)
{
m_clientSocket.Send(byData);
|
by: O.B. |
last post by:
In the example below, I'm trying to convert a fixed byte array to a
string. I get an error about needing to use "fixed" but I have no clue
where to apply it. Help?
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
|
by: Colin J. Williams |
last post by:
The Library Reference has
strip( )
Return a copy of the string with the
leading and trailing characters removed.
The chars argument is a string
specifying the set of characters to be
removed. If omitted or None, the chars
argument defaults to removing
whitespace. The chars argument is not a
|
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...
| |
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...
|
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. ...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
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...
|
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...
|
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...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |