Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > replacing substrings within strings

Reply
Thread Tools

replacing substrings within strings

 
 
Diez B. Roggisch
Guest
Posts: n/a
 
      02-14-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> Diez B. Roggisch:
>> That's the price to pay for immutable strings.

>
> Right, but CPython has array.array("c") too. Using Diez Roggisch's
> code:


Ahhh, ze arrayz. I alwayz forget about the arrayz.

Diez
 
Reply With Quote
 
 
 
 
Paul McGuire
Guest
Posts: n/a
 
      02-14-2007
On Feb 14, 6:08 am, "amadain" <(E-Mail Removed)> wrote:
> Hi
> I was wondering if there was a nicer way to swap the first 2
> characters in a string with the 4th and 5th characters other than:
>
> darr=list("010203040506")
> aarr=darr[:2]
> barr=darr[4:6]
> darr[:2]=barr
> darr[4:6]=aarr
> result="".join(darr)
>
> The above code works fine but I was wondering if anybody had another
> way of doing this?
>
> A


"4th and 5th characters" -> darr[4:6]

You must be referring to the leading '0' as the 0th character, then.

-- Paul

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Replacing substrings with images in GUI (parser) Karsten Wutzke Java 3 03-20-2008 12:49 AM
Finding and Replacing Substrings In A String DarthBob88 C Programming 7 09-23-2007 03:14 PM
Replacing large number of substrings Will McGugan Python 3 09-04-2005 10:17 PM
Replacing palindrome substrings of an input string with a given string Tung Chau C Programming 1 08-06-2004 07:27 PM
Replacing palindrome substrings of an input string with a given string. Any effecient algorithm? Tung Chau C Programming 0 08-06-2004 10:18 AM



Advertisments