472,992 Members | 3,294 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,992 software developers and data experts.

replace characters in a string

hi!

i want to replace these characters:
Expand|Select|Wrap|Line Numbers
  1. sex_m-designer_bw-size_42
so that i have the argument string:
Expand|Select|Wrap|Line Numbers
  1. sex=m&designer=bw&size=42 
i am working under zope 3.
glad for any help you can give me (i am veryyyy new in python, so please speak slow).

thank you,
steven, vienna
Oct 11 '07 #1
2 25176
bartonc
6,596 Expert 4TB
hi!

i want to replace these characters:
Expand|Select|Wrap|Line Numbers
  1. sex_m-designer_bw-size_42
so that i have the argument string:
Expand|Select|Wrap|Line Numbers
  1. sex=m&designer=bw&size=42 
i am working under zope 3.
glad for any help you can give me (i am veryyyy new in python, so please speak slow).

thank you,
steven, vienna
Here, again, the replace() method of a string object will do the job nicely:
Expand|Select|Wrap|Line Numbers
  1. >>> s = "sex_m-designer_bw-size_42"
  2. >>> s = s.replace('_', '=')
  3. >>> s = s.replace('-', '&')
  4. >>> s
  5. 'sex=m&designer=bw&size=42'
  6. >>> 
Here, I have used Python's interactive interpreter (denoted by the '>>>' prompt) to run off a quick test of the idea. In interactive mode, all of the built-in types (most of which are true objects in the OOP sense of the term) and functions are available.

Hope I spoke slowly enough,
Barton
Oct 11 '07 #2
Barton,

you are the man!

you saved my day!
(and kept the doctor away)

hurray.
Oct 11 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Eric Lilja | last post by:
Hello, I had what I thought was normal text-file and I needed to locate a string matching a certain pattern in that file and, if found, replace that string. I thought this would be simple but I had...
4
by: Locusta | last post by:
Hello, I have been struggeling for replacing a string in a string. The snippet from the program below replaces the <, & and > with the XML equivalent values. In the program, I allocate space...
3
by: JPSutor | last post by:
I want to be able to have a user type in a password to a text box and 1.) Capture the characters entered 2.) Replace typed chars with "*"
4
by: jpierson | last post by:
Hi, I'm having a few problems with the replace function for replacing characters in a textbox. "C:\" is the string i am tryin to remove ,with it a command I am sending does not work. ...
11
by: jarod1701 | last post by:
Hi, i'm currently trying to replace an unknown string using regular expressions. For example I have: user_pref("network.proxy.http", "server1") What do I have to do to replace the...
18
by: Umesh | last post by:
Do you have any answer to it? thx.
3
by: stephcsh | last post by:
Hi, I wanted to copy a data from table1 in db1 to table2 in db2, which has the same structure, with the PosgreSQL dblink funtion. The fields for both the tables are: id, first_name, last_name. ...
4
by: chriskaza81 | last post by:
hello i am very new in xsl ,xml so ....forgive me if i make spuped questions.. well i have the string e.g. <script> blabla bla </script> i want to replace in xsl the ...
4
by: vimalvisves | last post by:
Hi Friends, Any one know how to replace query string by slash delimeters, for example i want to replace query string www.websiteurl.com/PageName.aspx?Param1=Attribute1&Param2=Attribute2 as...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

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.