473,790 Members | 2,481 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2188
On Thu, 28 Jun 2007 15:32:01 -0700, Harry V
<Ha****@discuss ions.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****@discuss ions.microsoft. comwrote in message
news:61******** *************** ***********@mic rosoft.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****@discuss ions.microsoft. comwrote in message
news:61******** *************** ***********@mic rosoft.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
4719
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 invalid digits (~`!#$%^&*()+=?/). This is not working yet, I don't know why. In addition, I would like both fields to require from 1 to 12 digits for submition to continue. The text field also Lowers Case, can you tell me how to do the same on...
13
4812
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 93120 or 93121 or 93130 or 93140 or 93150 or 93160 or 93190 or 93199 or 93199 or 93401 or 93402 or 93403 or 93405 or 93406 or 93407 or 93408 or 93409 or 93410 or 93412
3
3381
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 the current TLDs), and allow for addresses with or without trailing slashes or page addresses. Anybody have any ideas on how to get this to work in Netscape? I suspect it has something to do with the regular expression, but I can't get it to...
3
18096
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 such as CLOCK$, AUX, CON, NUL, PRN, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, LPT9? There is a C++ implementation of it at
3
21800
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 loop too many times in my code already.
4
2598
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 figured since all the panel data is still being sent through the postbacks, instead of using Sessions, or HttpContext, I could just take the values from the textboxes. This all works fine, except for security. I realized that I could inject...
1
4008
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. Depends on the pull down list selection, I use script.aculo.us to validate the user input before submit and pass the necessary data, such as contact type, contact information and ranking to a php program for updating. This form should allow multiple...
4
1781
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 valid!"); form1.txtEmail.focus();
2
1702
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 26 02 34 E8 AA 20 76 97 51 28 50 76 38 64 49 00 58 02 02 C7 88 01 C7 88 AA 50 76 38 64 49 20 76 97 51 28 D8 07 04 18 13 10 2F 00 00 10 0A 06 0A 06 06 0A 06 0A 06 06 06 06 06 06 06 06 73 74 69 9C 19 Where the line reads 68 bytes, I need to...
0
9512
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9986
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9021
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7530
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6769
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5422
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4094
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3707
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.