Hey Guys!
As the title already says, I am trying to replace a singe digit (In my case zero) if there is no other number in the same field. The column is "string"
I already tried this: Replace ($feature.test, '0', 'test')
Unfortunately, it replaced all zeros, which I don't want.
Thanks a lot!!
Solved! Go to Solution.
You could use Iif and check the explicit value using the "==" operator. That way only features where the field is equal to 0 get the replacement text, but will otherwise return the original value.
return Iif($feature.test == '0', 'test', $feature.test)
You could use Iif and check the explicit value using the "==" operator. That way only features where the field is equal to 0 get the replacement text, but will otherwise return the original value.
return Iif($feature.test == '0', 'test', $feature.test)
Maybe someone else can code a more elegant evaluation but based on your sample screenshot, it looks like you need to verify that only *one* zero is present in the value so you need to evaluate all the characters in the value before deciding whether or not to alter its value. Something like thisL
var counter = 0;
var stringLen = 0;
var theString = "23405751";
stringLen = Count(theString) - 1;
for(var z=0; z<stringLen; z++) {
if (Mid(theString,z,1) == "0") {
counter++;
}
}
if (counter > 1) {
return 'There was more than one zero';
} else {
return 'There was only one zero';
}
Paste this code into the Playground and add/subtract zeros from the string to see it.
Hi,
As Steve said, you need to make sure you are changing the 0-only numbers, in other words, a single-digit number/string of a zero will have a value of 0!
Convert the column string to a number and if its value=0 then this means it's a one-digit string of zero>>>replace it, otherwise, return the original value!
Return Iif(Number($feature.test)==0, "test" , $feature.test)
Cheers,
Thanks a lot, guys!
I was able to change it.