I need to split a string that has the pattern: "10XX-11XX - ABCD - EFGH".


 Its necessary to keep in separeted values:

10XX-11XX

ABCD

EFGH


So, I'm using String_Split with the delimiter: " - "

It seems however that the delimiter that is being used is "-".


Anyone has had the same issue? How was solved?

Thanks in advance.



Solution

String split works with a single character. If you write " - " it will split in either " " or "-". What is happening is that consecutive delimiters are interpreted as one so it seems it is spliting with "-" but the space are also disappearing.

The fastest way to go around it is replacing " - " by a single not used character like "#" and then split by "#".

String_Split(Replace(String," - ","#"),"#")
Solution

Hi,

As you have "-" and " - ", you can do a replace before to remove all spaces and then the string split, separating by "-".


Example:

1 - Replace (String, " ", "")
2 - String_Split (String, "-")


I hope to help