How to split a line ONLY after the first separator instance?

I have this code:

strInfo = "3101234567 Ryan Maybach" Dim varSplit As Variant varSplit = Split(strInfo, " ") strPhoneNumber = varSplit(0) strOwner = varSplit(1) 

So strPhoneNumber = "3101234567" and strOwner = "Ryan"

I want to make strOwner = "Ryan Maybach", the full name, not just the first name.

How to split strInfo string in first space instance? "?

+8
source share
1 answer

From the MSDN documentation for the split function :

By default, or when Limit is -1, the Split function splits the input string each time a separator string appears and returns substrings in the array. When the Limit parameter is greater than zero, the Split function breaks the string at the first occurrence of the Limit -1 separator and returns an array with the resulting substrings.

If you want to divide only by the first separator, you must specify 2 as the maximum number of parts.

 Split(expression, [ delimiter, [ limit, [ compare ]]]) 
+12
source

All Articles