Split a string with two tokens

B

bg_ie

Hi,

I want the first match in a string, which I do as follows -

Dim strArray As Variant
strArray = Split(str, Chr(10), 2)

then strArray stores my value (I only want the first string before my
token)

The problem is, I also want to use Chr(13) as a token in this splitting
operation. How do I do this?

Thanks,

Barry.
 
T

Tony Jollans

What is wrong with this?

strArray = Split(str, Chr(13), 2)

Or do you mean something different? Perhaps ..

strArray = Split(str, Chr(10) & Chr(13), 2)

.. or ..

Split(Split(a, Chr(10), 2)(0), Chr(13))
 
J

Jonathan West

Tony Jollans said:
What is wrong with this?

strArray = Split(str, Chr(13), 2)

Or do you mean something different? Perhaps ..

strArray = Split(str, Chr(10) & Chr(13), 2)

.. or ..

Split(Split(a, Chr(10), 2)(0), Chr(13))

I suspect that if Barry wants to split at every Chr(10) and every Chr(13)
then a better approach would be to first replace every Chr(10) with a
Chr(13) and then split on Chr(13), like this

Dim strArray As Variant
Dim strTemp as String
strTemp = Replace(str, Chr(10), Chr(13)
strArray = Split(strTemp, Chr(13), 2)


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top