473,394 Members | 1,178 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,394 software developers and data experts.

How C# Regex to express "IDENTIFIER = ON/OFF"

User has a input as "SwitchName = ON" or "SwitchName = OFF", how to use C#
Regex to get SwitchName and the value?

Regex.Match(line, @"(\S+) = {ON|OFF}") does not work.
Dec 14 '05 #1
2 2663
James,

Why bother using a regular expression? Why not just parse based on the
equal sign and then assign to a key/value pair?

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"James" <ja********@hotmail.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
User has a input as "SwitchName = ON" or "SwitchName = OFF", how to use C#
Regex to get SwitchName and the value?

Regex.Match(line, @"(\S+) = {ON|OFF}") does not work.

Dec 14 '05 #2
Use the following regex : ^(\w+?)\s*=\s*(ON|OFF)\s*$
Match m=Regex.Match("mySwitch = ON",@"^(\w+?)\s*=\s*(ON|OFF)\s*$");
MessageBox.Show("switchname = "+m.Groups[1]);
MessageBox.Show("switch = "+m.Groups[2]);

Hope it helps,

Ludovic SOEUR.
"James" <ja********@hotmail.com> a écrit dans le message de
news:%2***************@tk2msftngp13.phx.gbl...
User has a input as "SwitchName = ON" or "SwitchName = OFF", how to use C#
Regex to get SwitchName and the value?

Regex.Match(line, @"(\S+) = {ON|OFF}") does not work.

Dec 14 '05 #3

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

Similar topics

6
by: craigbeanhead | last post by:
Hi, I'm teaching myself C from K&R2. I've come across something that I really don't understand. When I try to compile the following code (in VC++7), I get an "undeclared identifier" error. When...
4
by: Stephen Corey | last post by:
I've got 2 classes in 2 seperate header files, but within the same namespace. If I use a line like: // This code is inside Class2's header file Class1 *newitem = new Class1(param1, param2); ...
1
by: Andy Crawford | last post by:
Even though I have set Strict Off, it is still on, thus causing this error. Here is the code in a templated Column of a DataGrid: (XPpro, Framework 1.1) <ItemTemplate> <TABLE width="100%">...
21
by: nicholas | last post by:
Although in my web.config I have <customErrors mode="off" /> I still get no detailed errors. How comes ? THX This is what I get: Server Error in '/mywebfolder'Application.
4
by: Gérard Talbot | last post by:
Hello fellow stylers, What would be the best CSS equivalent of MSIE's wrap="off" and wrap="hard"? hard Text is displayed with wordwrapping and submitted with soft returns and line feeds. ...
6
by: Christopher Lusardi | last post by:
How can I fix this? When I do the below I get the error message: "Cannot insert explict value for identity column in table 'Employees' when IDENTITY_INSERT is set to OFF." To get this message,...
1
by: mknoll217 | last post by:
I am recieving this error from my code: The multi-part identifier "PAR.UniqueID" could not be bound. The multi-part identifier "Salary.UniqueID" could not be bound. The multi-part identifier...
10
by: Kurda Yon | last post by:
Hi, I set the register_globals off and try to get my code working under the new conditions. I stuck on the following problem: Warning: Unknown(): Your script possibly relies on a session side-...
3
by: rdsandy | last post by:
Hi, I am using SQL Server 2005. I have this stored procedure below but it doesn't work. It is for an archiving process I am currently implementing. The RiskArchive table has fields ArchiveID...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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,...

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.