Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / June 2007

Tip: Looking for answers? Try searching our database.

Validate a substring from a list

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Harry V - 28 Jun 2007 23:32 GMT
Is it possible to validate a 2-character substring against a list of 13
2-character codes without a select statement to a table or parsing an array?  
Something like ... myChars in ("aa", "bb", "cc")...
Signature

Harry E Vermillion
IT2
Division of Wildlife
State of Colorado

Peter Duniho - 29 Jun 2007 00:52 GMT
> Is it possible to validate a 2-character substring against a list of 13
> 2-character codes without a select statement to a table or parsing an  
> array?
> Something like ... myChars in ("aa", "bb", "cc")...

What do mean by "parsing an array"?

You could just put your list of substrings to match in an array, then use  
Array.Exists() or Array.IndexOf() to see if the substring is in the  
array.  There are similar methods you could use with the List<> class.  
Alternatively, you could probably use the RegEx class to see if there's a  
match.  I think you can use a search string like "[aa|bb|cc|...]" on your  
string; if your string is only two characters long and there's a match,  
then you know your substring was one of the items in the RegEx.

Personally, I'd use the array look-up method, but I suppose if you're  
really against using an array or List<>, RegEx would do.

Basically, there's any number of ways to do what you want.  Without a more  
precise problem description, it's hard to offer anything other than very  
general advice.

Pete
Pramod Anchuparayil - 29 Jun 2007 07:09 GMT
Not sure if I quite understand what you are trying to do but something like
this should work.

           string[] twoCharString = { "AA", "BB", "CC", "DD" };
           MessageBox.Show((twoCharString.Contains("BB") ? "Yes" :
"Nope"));

You can use the Contains method of a string.

-Pramod Anchuparayil

> Is it possible to validate a 2-character substring against a list of 13
> 2-character codes without a select statement to a table or parsing an
> array?
> Something like ... myChars in ("aa", "bb", "cc")...
Harry V - 29 Jun 2007 16:06 GMT
THat should do it.  Thank you, sir.
Signature

Harry E Vermillion
IT2
Division of Wildlife
State of Colorado

> Not sure if I quite understand what you are trying to do but something like
> this should work.
[quoted text clipped - 11 lines]
> > array?
> > Something like ... myChars in ("aa", "bb", "cc")...

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
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.