Re: How to insert in a string @ a index

2007-09-11 Thread Karthik Gurusamy
On Sep 8, 11:02 am, [EMAIL PROTECTED] wrote: > Hi; > > I'm trying to insert XYZ before a keyword in a string. The first and > the last occurence of hello in the string t1 (t1="hello world hello. > hello \nwhy world hello") are keywords. So after the insertion of XYZ > in this string, the result sho

Re: How to insert in a string @ a index

2007-09-10 Thread Marc 'BlackJack' Rintsch
On Mon, 10 Sep 2007 00:29:50 -0700, Ant wrote: > On Sep 10, 3:15 am, "a.m." <[EMAIL PROTECTED]> wrote: >> Thanks guys for you help. I ended up doing this way (for the >> records)... >> >> t1 = "hello world hello. hello. \nwhy world hello" > ... > > Another approach may be to use the re module's s

Re: How to insert in a string @ a index

2007-09-10 Thread Ant
On Sep 10, 3:15 am, "a.m." <[EMAIL PROTECTED]> wrote: > Thanks guys for you help. I ended up doing this way (for the > records)... > > t1 = "hello world hello. hello. \nwhy world hello" ... Another approach may be to use the re module's sub function: import re t1 = 'hello world hello. hello. \nw

Re: How to insert in a string @ a index

2007-09-09 Thread a.m.
Thanks guys for you help. I ended up doing this way (for the records)... t1 = "hello world hello. hello. \nwhy world hello" while indexhttp://mail.python.org/mailman/listinfo/python-list

Re: How to insert in a string @ a index

2007-09-09 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : > Hi; > > I'm trying to insert XYZ before a keyword in a string. Then forget about it. Python's strings are immutable. (snip) > The python doesn't supports t1[keyword_index]="XYZhello" (string > object assignment is not supported). How do I get to this problem? Any >

Re: How to insert in a string @ a index

2007-09-08 Thread David
On 9/8/07, Zentrader <[EMAIL PROTECTED]> wrote: > Same solution as above, but if you just want "Hello" and to not > include words containing "Hello", i.e. "Helloing" or "Unhello", then > you want to include a leading and/or trailing space. You can also use the re (regular expression) module to sea

Re: How to insert in a string @ a index

2007-09-08 Thread Zentrader
Same solution as above, but if you just want "Hello" and to not include words containing "Hello", i.e. "Helloing" or "Unhello", then you want to include a leading and/or trailing space. lit=" hello" ## note added space t1="nothello world hello. hello \nwhy world hello" start = t1.find(lit) t2 = t

Re: How to insert in a string @ a index

2007-09-08 Thread David
On 9/8/07, David <[EMAIL PROTECTED]> wrote: > > The python doesn't supports t1[keyword_index]="XYZhello" (string > > object assignment is not supported). How do I get to this problem? Any > > sugguestions? > > Build a new string var using slicing. eg: > > t1 = t1[:keyword_index] + "XYZhello" + [key

Re: How to insert in a string @ a index

2007-09-08 Thread David
> The python doesn't supports t1[keyword_index]="XYZhello" (string > object assignment is not supported). How do I get to this problem? Any > sugguestions? Build a new string var using slicing. eg: t1 = t1[:keyword_index] + "XYZhello" + [keyword_index] Or use string formatting: t1 = "your text

How to insert in a string @ a index

2007-09-08 Thread lolu999
Hi; I'm trying to insert XYZ before a keyword in a string. The first and the last occurence of hello in the string t1 (t1="hello world hello. hello \nwhy world hello") are keywords. So after the insertion of XYZ in this string, the result should be t1 = "XYZhello world hello. hello \nwhy world XYZ