• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 176
  • Last Modified:

seperate string into array

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?
0
antonioking
Asked:
antonioking
  • 3
2 Solutions
 
Rgonzo1971Commented:
Hi,

Use Split(strKeyAccounts, ",")


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

Regards
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
yes, using the split function
http://www.w3schools.com/vbscript/func_split.asp

but, you can do simpler, a one-liner:
http://www.w3schools.com/vbscript/func_instr.asp

blnKeyAccount  = instr(1, "," & strKeyAccounts & ",",  "," & strMyString & "," ) > 0
0
 
antoniokingAuthor Commented:
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
0
 
antoniokingAuthor Commented:
Maybe I should have used Google first!
http://support.microsoft.com/kb/266289

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

0
 
antoniokingAuthor Commented:
Thank you gentlemen, both replies contributed to solving my issue.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now