seperate string into array

Posted on 2014-08-27
Last Modified: 2014-08-27
I have a string "strKeyAccounts" that comprised of words seperated by commas

I'd like to return set a boolean as true if another string is found within the string 'strKeyAccounts'

For example..

If strMyString = array(strKeyAccounts) then blnKeyAccount = true

I'm not too sure how I can break the string strKeyAccounts into an actual array?
Question by:antonioking
    LVL 47

    Assisted Solution


    Use Split(strKeyAccounts, ",")

    Split(strKeyAccounts, ",")(0) for the first element

    LVL 142

    Accepted Solution

    yes, using the split function

    but, you can do simpler, a one-liner:

    blnKeyAccount  = instr(1, "," & strKeyAccounts & ",",  "," & strMyString & "," ) > 0

    Author Comment

    Split(strKeyAccounts, ",")(0) for the first element
    The amount of elements will be changing.

    blnKeyAccount  = instr(1, "," & strKeyAccounts & ",",  "," & strMyString & "," ) > 0

    If strKeyAccounts = word, word2, word3
    Then all this string is doing is looking for 'strMyString' in strKeyAccounts
    I actually want to look for word, word2 word3 etc inside strMyString

    so strKeyAccounts needs to be split into an array

    Author Comment

    Maybe I should have used Google first!

    So the code I've put together is...
    strKeyAccount = Split(strKeyAccounts, ",")
       For intKeyAccountCount = LBound(strKeyAccount) To UBound(strKeyAccount)
          If InStr(1,strMyString,Trim(strKeyAccount(intKeyAccountCount)))>0 then blnKeyAccount = True
       Next intKeyAccountCount

    Open in new window


    Author Closing Comment

    Thank you gentlemen, both replies contributed to solving my issue.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
    This script will sweep a range of IP addresses (class c only, and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now