Select to view content in your preferred language

Cutting text from one field to add to another field.

633
4
Jump to solution
12-15-2022 06:03 AM
NicoMcBrain
New Contributor II

I have  data in one field that looks like this 1 - EV-32818RC and it ranges with the first number reaching at max 74031 - EV-33160RC. What I am needing is the numbers before the hyphen cut and moved to another Field, only leaving behind the EV-*******. Both fields are text if that helps any.

0 Kudos
1 Solution

Accepted Solutions
dgiersz_cuyahoga
Occasional Contributor

I would use split()

field.split()[0] for the first part and field.split()[-1] for the last part, assuming there is always a space before and after the hyphen.

 

#CLE #sloth

View solution in original post

4 Replies
dgiersz_cuyahoga
Occasional Contributor

I would use split()

field.split()[0] for the first part and field.split()[-1] for the last part, assuming there is always a space before and after the hyphen.

 

#CLE #sloth
NicoMcBrain
New Contributor II

yes there is a space around the hyphen(both sides). This solution worked perfectly, I would like to understand the semantics behind how it worked. Like why [0] and [-1]

0 Kudos
dgiersz_cuyahoga
Occasional Contributor

split() creates a list of the strings using whitespace as the default separator.

"74031 - EV-33160RC" becomes ['74031', '-', 'EV-33160RC']

 You access contents of a list using the list index where 0 is the first item and -1 is the last item (The negative means start at the end and go through the list backwards)

field[1] and field [-2] in this case should both yield '-'

#CLE #sloth
NicoMcBrain
New Contributor II

Thank you.

0 Kudos