a simple string question

Zentrader zentraders at gmail.com
Fri Jul 27 18:31:25 CEST 2007


On Jul 27, 8:23 am, vedrandeko... at v-programs.com wrote:
> Hello,
>
> I have one question about string.I am trying to make an function to
> analyze line  of some text, this is my example: "HELLO;HELLO2:WORLD:",
>  if that function in this text find ";" and ":" ( in this example will
> find both)
>
> e.g  that function must return this:
>
> "HELLO;\nHELLO2:\n\t\t\t\t\t\t\tWORLD:"
>
> Regards,
> Vedran

You can use split twice
print text.split( ":" )
and then split the returned list items on ";".
You could also use text.find( ":" ), but that would be pretty much the
same thing only harder.  Also, you can step through the string one
character at a time and compare each character.  Finally, you can use
an re, (regular expression), but if you are still learning how to
parse strings, I don't think you want to get into re's.




More information about the Python-list mailing list