adding a hyphen between text on numbers

How do I add a hyphen between each word in a cell on numbers.


for example


from this


fine oval chain t-bar necklace with a pointed heart and mini heart charm


to this


fine-oval-chain-tbar-necklace-with-a-pointed-heart-and-mini-heart-charm.

MacBook Air 13″, macOS 10.13

Posted on Aug 9, 2021 10:44 PM

Reply
Question marked as Top-ranking reply

Posted on Aug 10, 2021 6:29 AM

Hi myfy,


The SUBSTITUTE function is your friend.


Formula in C2: SUBSTITUTE(B2," ","-")

That substitutes all spaces with hyphens.

Note that the formula does not specify occurrences, therefore it substitutes all spaces with hyphens.


To find out more, type = into a cell to bring up the Function Browser. Type the first few letters of a function:



Regards,

Ian.

2 replies
Question marked as Top-ranking reply

Aug 10, 2021 6:29 AM in response to myfy

Hi myfy,


The SUBSTITUTE function is your friend.


Formula in C2: SUBSTITUTE(B2," ","-")

That substitutes all spaces with hyphens.

Note that the formula does not specify occurrences, therefore it substitutes all spaces with hyphens.


To find out more, type = into a cell to bring up the Function Browser. Type the first few letters of a function:



Regards,

Ian.

Aug 10, 2021 6:36 AM in response to myfy

You also removed the hyphen in "t-bar".


If that text is in cell B2 then in cell C2 (for example)

=SUBSTITUTE(SUBSTITUTE(B2,"-","")," ","-")

If it is a column of cells with text like this then fill down with the formula in C2 to complete the column.


The inner SUBSTITUTE removes all existing hyphens, replacing them with nothing. The outer one changes all space characters into hyphens. If you find any cases where you get double hyphens it means there were two spaces there. You can use TRIM in the formula to fix any double spaces beforehand. I did that in the formula below


=SUBSTITUTE(SUBSTITUTE(TRIM(B2),"-","")," ","-")

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

adding a hyphen between text on numbers

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.