How can I split a string in LESS?

1.3k views Asked by At

In Stylus it's as easy as split('1/2', '/')[0] (which will split a string value at a certain delimiter, in the example it would return 1), in Sass I needed a huge function to do it. I don't see a way to natively do this in LESS or a function for doing this anywhere.

Anyone know of a way to do this?

1

There are 1 answers

1
Bass Jobsen On BEST ANSWER

It's silly more of these functions aren't built into preprocessors.

You should possible also explain why you need the split function.

Since Less version 2 you can easily add your own functions, see How to exend the Less compiler with a custom function leveraging a plugin

You should be able to add a split function which returns a list. As already explained by @Amadan you can use this list with loops and the built-in list functions.