On Jul 27, 11:26 am, Wildemar Wildenburger <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > >> If I understand you correctly you want to replace ";" by ";\n" and ":" > >> by ":\n\t\t\t\t\t\t\t". > >> Well guess what? The replace() method does just this. Have a read: > >> <URL:http://docs.python.org/lib/string-methods.html> > > > No,that's not what I need... > > When this function detect ";" or ":" ,it must append character "\n" or > > "\n\t" ahead ":" or ";" another e.g > > > 1) text="Hello world;Hello:Hello2" > > > 2) When function detect ";" or ":" it must append character "\n" or "\n > > \t" ahead ":" or ";", so that must look like this: > > > NEW TEXT : "Hello world;\nHello:\n\t\t\n\n\n\n\n\nHello2" > > Isn't that what I said? > > Please note that appending "\n" to ";" is the very same thing as > replacing ";" with ";\n". > > Also note that the your description of the desired behavior does not > match your example. You say "append "\n\t" after ":"", but thats not > what happens in your example. There you append "\n\t\t\n\n\n\n\n\n" > instead of "\n\t". That is confusing to me. Can you explain? > > /W
Confusing to me also. I read this as replace the first ";" with ";/ n", replace the first ":" with "\n\t\t\t\t\t\t\t", and on from there with different requirements. If that is the case then you have to locate the first, second, etc. and add/replace with the appropriate code. String.find and split would have to be used instead of a string.replace if you want to make different changes depending on if it is the first, second..., occurrence. -- http://mail.python.org/mailman/listinfo/python-list