Reputation: 177
I have a string "givenname surname". What I want is to turn this "surname, givenname". First I thought I would need to somehow place the surname at the first place, then replace the empty space with a comma and space.
I do not have any code yet :C sry.
Upvotes: 0
Views: 42
Reputation: 989
Agreed on @ansgar wiechers's comment.
$str = "Firstname Lastname"
$str -replace '(\w+)\s+(\w+)','$2, $1'
Output :
Lastname, Firstname
Upvotes: 1