Replace "dash" values in a field with new line- VB equivalent ofPython

C

Cathy James

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
 
N

Neil Cerutti

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")

str methods return new strings in Python, so you need to bind
something to them.

I don't know what the VB syntax above means, but if I pretend
that your string is bound to 'Name':

Name = Name.replace(" - ", "\n")
 
R

rusi

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
' Murray \n james \n Leo '

Which may be what you want.
I think you will prefer
[' Murray ', ' james ', ' Leo ']

Or still better
[part.strip() for part in line.split("-")] ['Murray', 'james', 'Leo']
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top