Split string in two strings

2 visualizaciones (últimos 30 días)
Dion Theunissen
Dion Theunissen el 10 de Ag. de 2022
Comentada: Stephen23 el 10 de Ag. de 2022
I have the following string, now I want to splits it up in 2 different strings like show in below:
STR = ["van Donk","Gerritsen","kooijman","Verliefde","Floré","Pengel","aan de Wiel","van der Hoeven","Hop","Boer","van Ewijk"]
What i want to create is
STR1 = ["van","","","","","","aan de","van der","","","van"]
STR2 = ["Donk","Gerritsen","kooijman","Verliefde","Floré","Pengel","Wiel","Hoeven","Hop","Boer","Ewijk"]
Anyone who can help me?
  2 comentarios
Walter Roberson
Walter Roberson el 10 de Ag. de 2022
Ummm... why? "van der Hoeven" is a complete surname. The surname is not "Hoeven" with "van der" being some kind of middle name. "van der Hoeven" should be sorted under v or V, not under H
Stephen23
Stephen23 el 10 de Ag. de 2022
"The surname is not "Hoeven" with "van der" being some kind of middle name."
The "van der" is not part of the main name, it is a tussenvoegsel:
which in Dutch is ignored when sorting, just like "von" and "zu" are ignored in German.
""van der Hoeven" should be sorted under v or V, not under H"
There are differing opinions on this:
So the required sort order depends mostly on where your users are from.

Iniciar sesión para comentar.

Respuestas (1)

Stephen23
Stephen23 el 10 de Ag. de 2022
Editada: Stephen23 el 10 de Ag. de 2022
str = ["van Donk","Gerritsen","kooijman","Verliefde","Floré","Pengel","aan de Wiel","van der Hoeven","Hop","Boer","van Ewijk"]
str = 1×11 string array
"van Donk" "Gerritsen" "kooijman" "Verliefde" "Floré" "Pengel" "aan de Wiel" "van der Hoeven" "Hop" "Boer" "van Ewijk"
tkn = regexp(str,'^(\w+\s+)*(\w+)$','tokens','once');
tkn = vertcat(tkn{:});
st1 = strtrim(tkn(:,1))
st1 = 11×1 string array
"van" "" "" "" "" "" "aan de" "van der" "" "" "van"
st2 = tkn(:,2)
st2 = 11×1 string array
"Donk" "Gerritsen" "kooijman" "Verliefde" "Floré" "Pengel" "Wiel" "Hoeven" "Hop" "Boer" "Ewijk"
  3 comentarios
Walter Roberson
Walter Roberson el 10 de Ag. de 2022
(.*)\s+(\S+)
What do you want to do if there are spaces after the last word?
Stephen23
Stephen23 el 10 de Ag. de 2022
str = ["van Donk","Gerritsen","kooijman","Verliefde","Floré","Pengel","aan de Wiel","van der Hoeven","Hop","Boer","van Ewijk","in 't veld"];
tkn = regexp(str,'^(.*?)\s*(\S+)$','tokens','once');
tkn = vertcat(tkn{:})
tkn = 12×2 string array
"van" "Donk" "" "Gerritsen" "" "kooijman" "" "Verliefde" "" "Floré" "" "Pengel" "aan de" "Wiel" "van der" "Hoeven" "" "Hop" "" "Boer" "van" "Ewijk" "in 't" "veld"

Iniciar sesión para comentar.

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by