473,398 Members | 2,165 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Validate a substring from a list

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 E Vermillion
IT2
Division of Wildlife
State of Colorado
Jun 28 '07 #1
3 2175
On Thu, 28 Jun 2007 15:32:01 -0700, Harry V
<Ha****@discussions.microsoft.comwrote:
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
Jun 28 '07 #2
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

"Harry V" <Ha****@discussions.microsoft.comwrote in message
news:61**********************************@microsof t.com...
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 E Vermillion
IT2
Division of Wildlife
State of Colorado
Jun 29 '07 #3
THat should do it. Thank you, sir.
--
Harry E Vermillion
IT2
Division of Wildlife
State of Colorado
"Pramod Anchuparayil" wrote:
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

"Harry V" <Ha****@discussions.microsoft.comwrote in message
news:61**********************************@microsof t.com...
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 E Vermillion
IT2
Division of Wildlife
State of Colorado
Jun 29 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Mike | last post by:
I'm using a script provided by e-mailanywhere, it's a little too big for me. There's 1 text field and 1 password field in a form. OnSubmit, I would like both fields to be validated to look for...
13
by: Eddie | last post by:
I need to validate a text input field. I just want to say if user enters 93101 or 93102 or 93103 or 93105 or 93106 or 93107 or 93108 or 93109 or 93110 or 93111 or 93116 or 93117 or 93118 or...
3
by: MJ | last post by:
For some reason the following script does not work in Netscape/Mozilla, but works fine in IE and Opera. It is supposed to check the syntax, make sure there is a valid TLD (yes, those are all of...
3
by: sheeeng | last post by:
Hi all, I know that we can check for invalid file name characters as shown at http://www.codeproject.com/useritems/reallyusefulpath.asp. But how can we check a string for invalid file name...
3
by: eso40043 | last post by:
Hello. Is there an easy one-line way to see if a list of strings contains at least one occurance of a substring? E.g. string_list= substring_list= I really don't want to loop, as I...
4
by: Brybot | last post by:
I have a form that i've split up into multiple asp:panels, each panel has a number of validators which work correctly. At on the last panel, i want to commit the data collected to a database. I...
1
by: SkipNRun | last post by:
I am a novice when comes to JavaScript, AJAX. I am working on a form, which will allow users to update their contact information. In order to make the form flexible, I need to use pull down list. ...
4
by: thupham | last post by:
I have 2 page: index.aspx next.aspx and the code in javascript to validate Email: function fnEmail() { if(checkEmail(form1.txtEmail.value)== false) { alert("Email is not...
2
by: =?Utf-8?B?QnJpYW4gQ29vaw==?= | last post by:
How do I validate that there are xx number of bytes data after a given spot. Here is an example; 2008/04/24 19:16:50 ARES_EINDICATION 010.050.082.108 117.3.01 (1d61) RX 68 bytes 1D 61...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.