Remove spaces between words


#1

Hello community,
I am sure this is a very easy operation but I am not sure how to do it?
I would like to remove spaces between words, only keep one.
Is there a node that do this?


#2

Essentially replace space" " with nothing ""


#3

Hi John,
Thanks for your answer, but what if we need to keep just one?
we can use a conditional statement with a number of possibilities but I dont think this is a smart way, is it?


#4

What do you mean? You can separate strings by spaces.
image

EDIT: Or do you mean you have excess spaces between words and you need to reduce them down to a single space?


#5

that exactly Nick!


#6

keep only one space in the string between words


#7

in excel there is one operation called trim, I just need the same here in dynamo.
Is there an easy way?


#8

Just take a look at the Dictionary by typing “trim” or “slice” or “split”, it could give you some clues to get started:
http://dictionary.dynamobim.com/#/Core/String/Action/TrimLeadingWhitespace
See also what’s in the Primer about strings:
http://dynamoprimer.com/en/04_The-Building-Blocks-of-Programs/4-4_strings.html


#9

Python would also work really well for this.
https://stackoverflow.com/questions/1546226/a-simple-way-to-remove-multiple-spaces-in-a-string-in-python


#10

Nice, I add it to my favourites, along with this one:


Edit: I just found another good one on this topic:


#11

Hello guys,
Sorry for my ignorance, I am new in dynamo and not familiar with python out of the box node editor.
Can anyone drop the graph here please?
Thank you very much in advance, you are amazing!


#12

We usually would rather take a look at what you have tried and answer the particular issues you encounter in doing it :slightly_smiling_face:


#13

Hello,
I have tried with all the nodes that you suggested in the dynamo primer, but none works.
Image attached


I have copied the code into a python script node in dynamo but no luck,
Image attached


#14

Is it normal that the sheet names list is empty in your first graph?


#15

it isn’t I just did not run in the image that I attached here,
see another shot


#16

String.Split gets you half way there. You just need to join your strings again with a single space.


#17

Thank you very much Nick, really appreciated
it seems to be working fine in dynamo but my sheet name in Revit is not changing,
do you know why, please see image attached


#18

Your String.Join node is giving you a sublist of names. You need to Flatten those values before setting the parameter for each sheet. (You can see all the names are being applied to the same sheet.)


#19

Amazing Nick, thank you very much for your help, you are a star!!!
Share graph just in case need it.

Trim spaces sheet name.dyn (6.6 KB)


#20

… The exact solution helped me as well: in order to have a multi-line text as room name, i had to add spaces. Then for scheduling, I’ve added a text-based instance parameter to room, which populates with the room name minus the spaces. Long story short, thank you @Nick_Boyts for the solution!