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

avoid case statement

c# vs2008
HI:
I have to replace a string with somevalue, I use the case
any Ideas how to better implement this (avoid regex if possible).
(was thinking of a dictionary?)
thanks
case "a"
myvar = "1a"
break
case "w"
myvar = "bb"
break
case "L"
myvar = "po"
break


Aug 26 '08 #1
4 1499
"raulavi" <ra*****@discussions.microsoft.comwrote in message
news:C6**********************************@microsof t.com...
c# vs2008
HI:
I have to replace a string with somevalue, I use the case
any Ideas how to better implement this (avoid regex if possible).
(was thinking of a dictionary?)
thanks
case "a"
myvar = "1a"
break
case "w"
myvar = "bb"
break
case "L"
myvar = "po"
break
You'be answered your own question. Use a dictionary.
--
Anthony Jones - MVP ASP/ASP.NET
Aug 26 '08 #2
On Aug 26, 11:29*am, raulavi <raul...@discussions.microsoft.com>
wrote:
c# vs2008
HI:
I have to replace a string with somevalue, I use the case
any Ideas how to better implement this (avoid regex if possible).
(was thinking of a dictionary?)
thanks
case "a"
* * myvar = "1a"
* *break
case "w"
* * myvar = "bb"
* *break
case "L"
* * myvar = "po"
* * break
A dictionary could be used, but I think that you need to explain
better your escenario, like if the possible values change both of the
to be replaced string and the replacing string.
In your code you are not "replacing" you are simply assigning
Aug 26 '08 #3
If all you need is a state machine, a dictionary works rather nicely.
Dictionary<string,stringeven better, as you end up typing the objects for
key and value.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#

or just read it:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think outside the box! |
********************************************
"raulavi" <ra*****@discussions.microsoft.comwrote in message
news:C6**********************************@microsof t.com...
c# vs2008
HI:
I have to replace a string with somevalue, I use the case
any Ideas how to better implement this (avoid regex if possible).
(was thinking of a dictionary?)
thanks
case "a"
myvar = "1a"
break
case "w"
myvar = "bb"
break
case "L"
myvar = "po"
break

Aug 26 '08 #4
thanks to all
the scenario is very basic...
long lists everywhere
there are many pair (case) every where in this c# code (framework 2.0) I
will love to use linq, but will wait for 3.0
I would like to organize them nicelly as:
listIn = "a,w,L..."
listOut = "1a,bb,po..."
myvar = for listIn use listOut;
(nice future feature eh?)

"Ignacio Machin ( .NET/ C# MVP )" wrote:
On Aug 26, 11:29 am, raulavi <raul...@discussions.microsoft.com>
wrote:
c# vs2008
HI:
I have to replace a string with somevalue, I use the case
any Ideas how to better implement this (avoid regex if possible).
(was thinking of a dictionary?)
thanks
case "a"
myvar = "1a"
break
case "w"
myvar = "bb"
break
case "L"
myvar = "po"
break

A dictionary could be used, but I think that you need to explain
better your escenario, like if the possible values change both of the
to be replaced string and the replacing string.
In your code you are not "replacing" you are simply assigning
Aug 26 '08 #5

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

Similar topics

26
by: Joe Stevenson | last post by:
Hi all, I skimmed through the docs for Python, and I did not find anything like a case or switch statement. I assume there is one and that I just missed it. Can someone please point me to the...
6
by: deanfamily11 | last post by:
I've set up a case statement to have my program determine where on the Cartesian plane a point the user enters is located. I keep getting the C2051 error when I compile. Any help? #include...
13
by: Sameer | last post by:
Hi friends, I am beginner in C++. I am using g++ compiler. below is my code which gives error as " invlid conversion from 'char' to 'const char*' ..Plz help me with this. #include <iostream.h>...
13
by: Fei Liu | last post by:
Hi Group, I've got a problem I couldn't find a good solution. I am working with scientific data files in netCDF format. One of the properties of netCDF data is that the actual type of data is only...
6
by: betbubble | last post by:
I need help on two questions: 1. Is temp table the only way to pass recordsets from a nested stored procedure to a calling stored procedure? Can we avoid temp tables in this case? 2. Are...
2
by: Angel Of Death | last post by:
I have a method. It takes some XML as a parameter. Depending on the content of the XML it should create a specific object and call a KNOWN method. So: public void PersistXml(string XmlData){} ...
6
by: Fir5tSight | last post by:
Hi All, I have a "SELECT" statement in a stored procedure that looks like the follows: ...
3
by: digz | last post by:
This is a very simplified version of something I am trying to understand. The State object holds the strings and maps , and I pass a reference to State to the process Function which manipulates it...
36
by: CK | last post by:
How do I write a set based query? I have a groupSets table with fields setId, idField, datasource, nameField, prefix, active Data: 1,someIDfield, someTable, someField, pre1, 1 2,someotherIDfield,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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
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...

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.