VB.NET - Find a Substring in an ArrayList, StringCollection or List(Of String)
Posted
by CJM
on Stack Overflow
See other posts from Stack Overflow
or by CJM
Published on 2010-06-07T09:59:53Z
Indexed on
2010/06/07
10:02 UTC
Read the original article
Hit count: 259
I've got some code that creates a list of AD groups that the user is a member of, with the intention of saying 'if user is a member of GroupX then allow admin access, if not allow basic access'.
I was using a StringCollection to store this list of Groups, and intended to use the Contains method to test for membership of my admin group, but the problem is that this method only compares the full string - but my AD groups values are formatted as cn=GroupX, etc...
.
I want to be easily able to determine if a particular substring (i.e. 'GroupX') appears in the list of groups. I could always iterate through the groups check each for a substring representing my AD group name, but I'm more interested in finding out if there is a 'better' way.
Clearly there are a number of repositories for the list of Groups, and it appears that Generics (List(Of String)
) are more commonly preferred (which I may well implement anyway) but there is no in-built means of checking for a substring using this method either.
Any suggestions? Or should I just iterated through the list of groups?
© Stack Overflow or respective owner