Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / December 2006

Tip: Looking for answers? Try searching our database.

Split a string with two tokens

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
bg_ie@yahoo.com - 14 Dec 2006 14:02 GMT
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.
Tony Jollans - 14 Dec 2006 14:43 GMT
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))

Signature

Enjoy,
Tony

> Hi,
>
[quoted text clipped - 12 lines]
>
> Barry.
Jonathan West - 14 Dec 2006 14:59 GMT
> What is wrong with this?
>
[quoted text clipped - 7 lines]
>
>    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)

Signature

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

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.