471,350 Members | 1,620 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 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 1456
"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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

26 posts views Thread by Joe Stevenson | last post: by
6 posts views Thread by deanfamily11 | last post: by
13 posts views Thread by Sameer | last post: by
6 posts views Thread by betbubble | last post: by

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.