Dynamo for Civil3D - Modifying text in a list (only certain items)

Hello,

I have a list of numbers in Dynamo. Some are positive, others negative:

List

I want to add a “+” sign in front of the positve numbers.
I’ve tried using the List.FilterByBoolMask node, but I can’t manage to combine the 2 IN and OUT lists without changing the order or deleting values.

Does anyone have a solution?

Thanks

Lilian

Hi @lfesslerBDUQ2 ,

Create a code block with:

input > 0 ? "+"+input:""+input;

This code block expects a number (double or integer) as input and returns a string.

1 Like

The input must be a number, the output becomes a string or a number.

Hi @Daan

Thank you for your answer.

I test it, but it doesn’t work:
list2

Sorry, I want to share my Dynamo-file, but I can’t, because I’m a new user on the forum

Hi @Anton_Huizinga

Sorry, but do you speak from the input of wich node ?

In a code block: String.StartsWith(str, “-“, true)?str: “+”+str;

1 Like

The first code that Daan mentioned before edited. if you want to check if something is greater than, then it must be a number.
The output of that code resulted in a string if it adds a plus, and a number if it is not changed.

The new code example will work, if you do not copy the code. In your example, you have fancy curled quotes due to copying from the forum, replace them with the normal " quotes which you find on the keyboard.

1 Like

@Anton_Huizinga Thank you, it’s work great, I don’t see that the quotes was not normal :wink:

1 Like

Since I answered from mobile it seems like it automatically changed to those, I changed them such that they can be copied pasted normally.

3 Likes