Replace "dash" values in a field with new line- VB equivalent of Python
rusi
rustompmody at gmail.com
Tue Mar 19 11:59:12 EDT 2013
On Mar 19, 8:36 pm, Cathy James <nambo... at gmail.com> wrote:
> Dear All,
> I need some assistance with Python so that values in the "Name" field e.g.
> Murray - James - Leo can be labeled as:
>
> Murray
> James
> Leo
>
> with a new line replacing every dash.
>
> Basically I need the equivalent of this VB in Python:
> replace ( [Name] , "-", vbNewLine)
>
> I tried this but no luck:
>
> str.[Name].replace("-", "\n")
> str.[Name].replace("-", \n)
> [Name].replace("-", \n")
>
> Your help is appreciated
What do you mean by 'field'?
Is it a text file? html form? Some kind of gui?
As such 'field' has no meaning in python without further qualification
Anyways here is a small sample that may start you off
>>> line=" Murray - james - Leo "
>>> line.replace("-", "\n")
' Murray \n james \n Leo '
Which may be what you want.
I think you will prefer
>>> line.split("-")
[' Murray ', ' james ', ' Leo ']
Or still better
>>> [part.strip() for part in line.split("-")]
['Murray', 'james', 'Leo']
>>>
More information about the Python-list
mailing list