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 2518
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 can't figure out how to convert the char array back to a
string. Whether I use .ToString() from the...
|
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 deserialize
on "<Field1></Field1>". So the questions are:
1) Why does serializer produce...
|
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 usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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: 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...
|
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |