Select to view content in your preferred language

Move last word to first word in field calculator

2328
12
Jump to solution
10-21-2021 08:50 AM
kat_h
by
Emerging Contributor

Hi!

I'm trying to give watercourse names their French name from their English name, so I need to change the order of words a bit such as:

Wind Ruisseau -> Ruisseau Wind

I can remove Ruisseau with !Nom![:-9], but I can't figure out how to place it in the front with a space.

Some watercourse names hare three words like

West Wind Ruisseau 

Would using an UpdateCursor be more simple than trying to figure out an expression in the Field Calculator?

 

Thanks!

0 Kudos
1 Solution

Accepted Solutions
JoshuaBixby
MVP Esteemed Contributor
>>> s = "Wind Ruisseau"
>>> " ".join(s.split()[::-1])
'Ruisseau Wind'
>>>

View solution in original post

12 Replies
ABishop
MVP Regular Contributor

"West Wind"+' ' +"Ruisseau" 

Amanda Bishop, GISP
0 Kudos
kat_h
by
Emerging Contributor

I need to do it for thousands of unique names that end with "Ruisseau" and make them start with "Ruisseau"

0 Kudos
ABishop
MVP Regular Contributor

Are the unique names in a specific field you can call out?  In this case, you could use the field calculator  to do this:

"Ruisseau"+' ' +[FIELD NAME]

Amanda Bishop, GISP
kat_h
by
Emerging Contributor

Ah yes, that's a much more simple solution than I was thinking. I think this should work, thank you!

JoshuaBixby
MVP Esteemed Contributor
>>> s = "Wind Ruisseau"
>>> " ".join(s.split()[::-1])
'Ruisseau Wind'
>>>
kat_h
by
Emerging Contributor

Thanks! I'll give this a try as well. 

Can I make my field equal s?  like  s = !Nom! so it selects my selected rows from this field?

0 Kudos
kat_h
by
Emerging Contributor

Just tried with field name, which absolutely works! Thanks kindly. 

0 Kudos
kat_h
by
Emerging Contributor

Hi Joshua,

Is there a way to I could keep the order of the middle words when there are three words in the string?

For example, this expression also reverses the names of the other words:

'West Wind Ruisseau' becomes 'Ruisseau Wind West'  

and I would like 'Ruisseau West Wind'

0 Kudos
BlakeTerhune
MVP Regular Contributor

Here's another solution to consider.

s = "West Wind Ruisseau"
s = s.rsplit(" ", 1)
last_word = s.pop()
s = " ".join([last_word] + s)