Hello,
I'm a newbie on Arcade, i very like this language but it's new for me and I have some difficulties to find my happiness!
I would like to rearrange a string Address in a field, I would like put the last word in 1st place and the other after (in parenthesis)
For example: RUE GEORGES BONNAC will be BONNAC (RUE GEORGES).
I Think, I have to split my string et count the words but i got a dictionary error and I don't what to do.
Thank you everybody.
Solved! Go to Solution.
Hi KARIM LABIDI ,
I think this could do the trick:
var township = FeatureSetByName($datastore, "GDB.SIGWRITER.FV_TRONC_L", ["NOM_VOIE"], True);
var intersectLayer = Intersects(township, $feature);
var cnt = Count(intersectLayer);
if (cnt > 0) {
var feat = First(intersectLayer);
var nomvoie = feat["NOM_VOIE"];
if (IsEmpty(nomvoie)) {
return "no NOM VOIE"; // or perhaps return null
} else {
var words = Split(nomvoie, " ");
var cnt2 = Count(words);
var lastword = words[cnt2-1];
if (cnt2 > 1) {
var otherwords = [];
for (var i = 0; i < cnt2-1; i++) {
otherwords[Count(otherwords)] = words[i];
}
return lastword + " (" + Concatenate(otherwords, " ") + ")";
} else {
return lastword;
}
}
} else {
return "No township found"; // or perhaps return null
}
I tested with this code:
// RUE GEORGES BONNAC would be BONNAC (RUE GEORGES)
var nomvoie = "RUE GEORGES BONNAC";
if (IsEmpty(nomvoie)) {
return "no NOM VOIE"; // or perhaps return null
} else {
var words = Split(nomvoie, " ");
Console(words);
var cnt2 = Count(words);
var lastword = words[cnt2-1];
if (cnt2 > 1) {
var otherwords = [];
for (var i = 0; i < cnt2-1; i++) {
otherwords[Count(otherwords)] = words[i];
}
return lastword + " (" + Concatenate(otherwords, " ") + ")";
} else {
return lastword;
}
}
... which returned this:
BONNAC (RUE GEORGES)
Hi kbm_admin ,
Sure. Can you try this?
var township = FeatureSetByName($datastore, "GDB.SIGWRITER.FV_TRONC_L", ["NOM_VOIE"], True);
var intersectLayer = Intersects(township, $feature);
var cnt = Count(intersectLayer);
if (cnt > 0) {
var feat = First(intersectLayer);
var nomvoie = feat["NOM_VOIE"];
if (IsEmpty(nomvoie)) {
return "no NOM VOIE"; // or perhaps return null
} else {
var words = Split(nomvoie, " ");
Console(words);
var cnt2 = Count(words);
var lastword = words[cnt2-1];
var add = "";
Console(Find("'", lastword));
if (Find("'", lastword) > -1) {
var arr = Split(lastword, "'");
add = " " + arr[0] + "'";
lastword = arr[1];
}
if (cnt2 > 1) {
var otherwords = [];
for (var i = 0; i < cnt2-1; i++) {
otherwords[Count(otherwords)] = words[i];
}
return lastword + " (" + Concatenate(otherwords, " ") + add + ")";
} else {
return lastword;
}
}
} else {
return "No township found"; // or perhaps return null
}
Hi kbm_admin ,
There are a couple of things that may be going wrong here:
Try this:
var township = FeatureSetByName($datastore, "GDB.SIGWRITER.FV_TRONC_L", ["NOM_VOIE"], True);
var intersectLayer = Intersects(township, $feature);
var cnt = Count(intersectLayer);
if (cnt > 0) {
var feat = First(intersectLayer);
var nomvoie = feat["NOM_VOIE"];
if (IsEmpty(nomvoie)) {
return "no NOM VOIE"; // or perhaps return null
} else {
var words = Split(nomvoie, " ");
// define what to return, let's say you want to first word
return words[0];
}
} else {
return "No township found"; // or perhaps return null
}
HI Xander, thanks for your answer. My problem is that I want the last word of the address, return it on the First Place and concatenate the other part of the address to return it after the First place. I don't know if it's clear , i put an example : RUE GEORGES BONNAC would be BONNAC (RUE GEORGES).
Thanks Xander
Hi KARIM LABIDI ,
I think this could do the trick:
var township = FeatureSetByName($datastore, "GDB.SIGWRITER.FV_TRONC_L", ["NOM_VOIE"], True);
var intersectLayer = Intersects(township, $feature);
var cnt = Count(intersectLayer);
if (cnt > 0) {
var feat = First(intersectLayer);
var nomvoie = feat["NOM_VOIE"];
if (IsEmpty(nomvoie)) {
return "no NOM VOIE"; // or perhaps return null
} else {
var words = Split(nomvoie, " ");
var cnt2 = Count(words);
var lastword = words[cnt2-1];
if (cnt2 > 1) {
var otherwords = [];
for (var i = 0; i < cnt2-1; i++) {
otherwords[Count(otherwords)] = words[i];
}
return lastword + " (" + Concatenate(otherwords, " ") + ")";
} else {
return lastword;
}
}
} else {
return "No township found"; // or perhaps return null
}
I tested with this code:
// RUE GEORGES BONNAC would be BONNAC (RUE GEORGES)
var nomvoie = "RUE GEORGES BONNAC";
if (IsEmpty(nomvoie)) {
return "no NOM VOIE"; // or perhaps return null
} else {
var words = Split(nomvoie, " ");
Console(words);
var cnt2 = Count(words);
var lastword = words[cnt2-1];
if (cnt2 > 1) {
var otherwords = [];
for (var i = 0; i < cnt2-1; i++) {
otherwords[Count(otherwords)] = words[i];
}
return lastword + " (" + Concatenate(otherwords, " ") + ")";
} else {
return lastword;
}
}
... which returned this:
BONNAC (RUE GEORGES)
Yeah Xander it works perfectly. Thank you so much!
Hi KARIM LABIDI ,
Glad to hear that it works. Could you mark the post as the correct answer? If you need any additional explanation just let me now.
Hi Xander,
do you know if it possible to add an element in the split? Sometimes , my strings are like this : AVENUE D'ARES so I need to keep ARES and not D'ARES. I would like find at the end :ARES (AVENUE D'). Do you know if it's possible to have this? Maybe with a replace for the ' by a " " but i'm not sure.
If you have a idea about this problem, I will be grateful.
Hi kbm_admin ,
Sure. Can you try this?
var township = FeatureSetByName($datastore, "GDB.SIGWRITER.FV_TRONC_L", ["NOM_VOIE"], True);
var intersectLayer = Intersects(township, $feature);
var cnt = Count(intersectLayer);
if (cnt > 0) {
var feat = First(intersectLayer);
var nomvoie = feat["NOM_VOIE"];
if (IsEmpty(nomvoie)) {
return "no NOM VOIE"; // or perhaps return null
} else {
var words = Split(nomvoie, " ");
Console(words);
var cnt2 = Count(words);
var lastword = words[cnt2-1];
var add = "";
Console(Find("'", lastword));
if (Find("'", lastword) > -1) {
var arr = Split(lastword, "'");
add = " " + arr[0] + "'";
lastword = arr[1];
}
if (cnt2 > 1) {
var otherwords = [];
for (var i = 0; i < cnt2-1; i++) {
otherwords[Count(otherwords)] = words[i];
}
return lastword + " (" + Concatenate(otherwords, " ") + add + ")";
} else {
return lastword;
}
}
} else {
return "No township found"; // or perhaps return null
}
Hi @XanderBakker,
yeah it works perfectly. Thank you so much. I very appreciate your help and your reactivity.
Thank a lot