I have one string that has two words in it:
Cat Dog
How can I split these up so I get:
Str1 = Cat
and Str2 = Dog
Please note this is for VB6.
To split a string by multiple spaces, call the split() method, passing it a regular expression, e.g. str. trim(). split(/\s+/) . The regular expression will split the string on one or more spaces and return an array containing the substrings.
The split() method splits a string into a list. You can specify the separator, default separator is any whitespace. Note: When maxsplit is specified, the list will contain the specified number of elements plus one.
To split a string by space or comma, pass the following regular expression to the split() method - /[, ]+/ . The method will split the string on each occurrence of a space or comma and return an array containing the substrings.
split() method to split a string by one or more spaces. The str. split() method splits the string into a list of substrings using a delimiter.
Use the Split function.
Dim output() As String
output = Split("Cat Dog", " ")
Would produce
output(0) = Cat
output(1) = Dog
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With