1

Please tell me how to split a string into parts, using as a separator a multichar string, not a single symbol

for example

array = MySplit("xdatayydatazzz", "data");

and result

array(0) = "x"
array(1) = "yy"
array(2) = "zzz"

2 Answers 2

4

Um, why not just use:

arr = Split("xdatayydatazzz", "data")

Just to be sure, I tested this, and it works as expected. Docs on Split here.

Sign up to request clarification or add additional context in comments.

3 Comments

you could not have tested it in VBA. the variable name array is illegal. the semicolon at the end of line is also illegal
It does work though. I wondered if it did, so thanks for checking!
Haha, true, I just tested the concept, not the exact spelling, thanks for the tip.
3

First do a replace on the string e.g. data with a chosen character e.g. @ and then split on that:

secondstring = Replace("xdatayydatazzz", "data", "@")

array = Split(secondstring, "@")

Could nest the Replace inside the Split to keep to one step.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.