Get first item from Split()

filur picture filur · Aug 31, 2015 · Viewed 78.8k times · Source

I use the SPLIT function to split a string which looks something like 1.23/1.15.

Right now it yields two cells, as it should. But how do I get a certain element from the result? I would like to do something like this:

SPLIT("1.23/1.15", "/")[0]

to extract 1.23. What is the correct syntax for that?

I tried using the INDEX function, without success: =INDEX(SPLIT("1.23/1.15", "/"), 0,0)

Answer

gar picture gar · Aug 31, 2015

You can use the index function to select which value to return. So to retrieve the second value from your example you could use:

=index(SPLIT("1.23/1.15", "/"), 0, 2)

The last argument says which column you wish to retrieve - 1 would retrieve the first value.

Alternatively you could use left / right and find to extract either value from your example. For example to get the first value you could use:

=left("1.23/1.15", find("/", "1.23/1.15"))