What I'm trying to do is trim an FQDN down to just the name of the asset.
For example, let's say I have a machine called "Desktop1.mycompany.com"
and I just want to have the value "Desktop1"
in another field.
I've done a trim command Trim(Left([ColumnwithFQDN],(InsStr(1,[ColumnwithFQDN],".")-1)))
and it works. It removes everything but the machine name.
However, I notice this list has some computer names without the FQDN and they're just showing up as "Desktop2"
. Obviously, this causes a #Func! error
.
My question is: is there any way to either skip anything that's not in the FQDN or have it just return the original value if the function fails?
I think I could do an IIf(IsNull)
command, but I'm not sure what I would be setting as the value to return.
The Trim
function removes leading and trailing spaces from a string, and neither a hostname nor an FQDN can contain such, so that function isn't needed here. Of course, you can apply it in the end, if you wish. The interesting part is the Left
function in this case. I suggest to use the following expression:
Left([ColumnwithFQDN], Len([ColumnwithFQDN]) - InStrRev(StrReverse([ColumnwithFQDN]), "."))
Same as with the solution of @HansUp, you have to be sure that [ColumnwithFQDN]
isn't Null.