Translated by moderator. See below the line for original post.
Hello,
I have a list of rooms with a parameter called “Clinic”. In 8 of them, this parameter is empty. From the values of this parameter, I want to extract the first one using only standard Dynamos nodes.
I’ve used String.Substring, but it returns a warning and null for those rooms where the “clinic” parameter is empty.
tengo una lista de habitaciones con un parametro “Clinica” en 8 de ellas este parametro esta vacio. De los valores de este parametro yo quiero sacar la primera inicial solo usando nodos de Dynamos estandar.
He usado String.Substring pero me devuelve una advertencia y null para aquellas habitaciones que tiene el parametro clinica vacio.
The official language here is English, which sadly is a technical requirement for search to work (annars skulle jag svara på svenska så att jag kunde öva). Please translate future posts using the service of your choosing (I like Google Translate) in the future, optionally keeping your native language in a separate follow on if so desired (doing so might help quite a bit should we ever get multi lingual support here). Thanks!
Could you explain what you are trying to achieve? If you want to extract the first item of each sublist, or the first sublist, you can use List.FirstItem with a different level set.
If you want to do the substring operation, but you do not want to get the error, you can use the Function.Apply with your now string.substring & settings part as the function input.
What is then exactly the problem? When the string is empty, it’s logical that when you ask it for the first letter it gives null because there is no first letter. If the problem is that it errors, see my suggestion above to prevent that.
Or, why not just filter out the clinic names which have no name, and handle them differently (or ignore them) by filtering them first using a List.FilterByBoolmask node.
You’re pretty close already. The Substring node will run successfully with no errors if you give it a length of 0. So you can just use a conditional to determine whether you want to return the first character (length = 1) or no character (length = 0).