How do I remove a line break from a string?

Hi everyone, still quite new to Dynamo here, and am having a small issue in formatting an element in Revit.

Right now, the code outputs a result as shown below:
13 1/4
"

What I would like it to be is: 13 1/4".

I have tried copying and pasting this section from the custom node into the homepage, and it works properly, and outputs 13 1/4" as a string.

The top (straight) part of the code works as intended, and I believe the error stems from either the circled node, or somewhere before it. In the circled node, I’m trying to combine 1/4 and " to make 1/4", but it appears that it is inserting a line break before the ", but I cannot see why this is happening. I have tried using the ‘+’ node instead of String.Concat, which appears to work the same way, but without having to join the strings at the end.

I also tried a (very basic) python script to try to remove the line break, but it would give me a (null) for the answer.

Import clr
mystring = IN[0]
mystring = mystring.replace(’\n’,’’).replace(’\r’,’’)
OUT = mystring

Can someone let me know what I’m missing here, or try to point me in the right direction?

Thanks!

Can you try this one ?

1 Like

I think the problem is String.Concat. It concatenates lists of strings. I’m guessing you really want to use the + node to join them.

You can also try…

x + y

in a code block :slight_smile:

(or obvs x + “”" etc. etc.)

2 Likes

It would be the best solution :). Actually I don’t know how could he end up having the string with 2 lines. So my script handles the result from there

Thanks for all the responses guys, unfortunately none of these work :confused:. Sorry it took so long, I wanted to try all combinations of everything you suggested.

Kevin, as a follow-up question, what data type does the python script output? It returned a null in my watch box. I tried using the code after using the concatenate nodes, the + nodes and the code block Mark suggested and got null every time.

Mark, I tried using x+y in a code block, and I have no idea what happened, but it gave me ‘1 1/4’ (without the "), and totally disregarded the ‘+12’ I was taking from the upper node chain.

Nick, I had already tried using the ‘+’ node, which I found to work the same way as the concatenate + join combination, and would still give me the " on the next line.

I really don’t know why my string ends up with 2 lines, I’m not even sure if it’s technically two lines because removing \n hasn’t worked the three different ways I tried it. What I’m confused about is why it works when I run it as a definition, but not in the custom node.

Can you show us the output of both strings before you join them? Does the fractional piece already have a line break in it?

String.Replace works for me.

For%20Forum

Here’s a picture of the watch boxes, I organised them to look like the original photo (sorry I can only upload 1 photo at a time). String replace was one of the methods I tried before, but I used your method and got the same thing. So it looks like there is a line break in the ‘fractional’ node, but I don’t see why. The original text read as 1’-1 1/4" with no line break anywhere. I will take another look at the nodes preceding the fractional node now and see if I can find the error.

In Fractional Inches and Quotation. The data structure is still a list. You should convert to string then concat with another string.

2 Likes

Thanks Kevin, this seems to have put me on the right path. It is currently giving me None null" in the final watch box, which although isn’t the result I wanted, has all the text on the same line. I spent the whole workday on this so I’ll take a crack at it in the morning and if I manage to solve it I’ll update you guys.

1 Like

why on earth a “n” letter replaces a break line string? thanks it worked for me