Click here to Skip to main content
15,888,984 members
Home / Discussions / C#
   

C#

 
AnswerRe: foreach simple question Pin
Ian Shlasko17-Sep-09 10:28
Ian Shlasko17-Sep-09 10:28 
QuestionRe: foreach simple question Pin
JollyMansArt17-Sep-09 12:04
JollyMansArt17-Sep-09 12:04 
AnswerRe: foreach simple question Pin
PIEBALDconsult17-Sep-09 12:08
mvePIEBALDconsult17-Sep-09 12:08 
QuestionRe: foreach simple question Pin
JollyMansArt17-Sep-09 12:15
JollyMansArt17-Sep-09 12:15 
QuestionRe: foreach simple question Pin
JollyMansArt17-Sep-09 12:22
JollyMansArt17-Sep-09 12:22 
AnswerRe: foreach simple question Pin
PIEBALDconsult17-Sep-09 13:06
mvePIEBALDconsult17-Sep-09 13:06 
AnswerRe: foreach simple question Pin
Ian Shlasko17-Sep-09 12:21
Ian Shlasko17-Sep-09 12:21 
AnswerRe: foreach simple question Pin
Luc Pattyn17-Sep-09 12:21
sitebuilderLuc Pattyn17-Sep-09 12:21 
if you need a list of translations, say a1->a2, b1->b2, c1->c2, ...
then instead of adding a1, a2, b1, b2, c1, c2, ... to a simple list
add (a1, a2), (b1, b2), (c1, c2), ... to either a simple list (that would take some class or struct to hold two items), or to a dictionary.
The net result would be you can iterate the entire collection (and use a foreach), you don't have to skip every other entry.

Dictionary<string,string> dict=new Dictionary<string,string>();
dict.Add("%USERNAME%", Environment.UserName);
dict.Add("%MACHINENAME%", Environment.MachineName);
...
// now translate a string s:
foreach(string key in dict.Keys) s=s.Replace(key, dict[key]);
// done


BTW: don't use ToString() on something that already is a string!

PS: letting Windows do the substitutions, as PIEBALD showed you, is the better approach in this case.

Smile | :)

Luc Pattyn

Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.

Local announcement (Antwerp region): Lange Wapper? Neen!


modified on Thursday, September 17, 2009 7:37 PM

AnswerRe: foreach simple question Pin
Christian Graus17-Sep-09 10:28
protectorChristian Graus17-Sep-09 10:28 
AnswerRe: foreach simple question Pin
PIEBALDconsult17-Sep-09 10:32
mvePIEBALDconsult17-Sep-09 10:32 
GeneralRe: foreach simple question Pin
Christian Graus17-Sep-09 12:03
protectorChristian Graus17-Sep-09 12:03 
GeneralRe: foreach simple question Pin
PIEBALDconsult17-Sep-09 12:05
mvePIEBALDconsult17-Sep-09 12:05 
GeneralRe: foreach simple question Pin
Christian Graus17-Sep-09 12:09
protectorChristian Graus17-Sep-09 12:09 
GeneralRe: foreach simple question Pin
Ian Shlasko17-Sep-09 12:30
Ian Shlasko17-Sep-09 12:30 
GeneralRe: foreach simple question Pin
JollyMansArt17-Sep-09 12:36
JollyMansArt17-Sep-09 12:36 
GeneralRe: foreach simple question Pin
PIEBALDconsult17-Sep-09 13:35
mvePIEBALDconsult17-Sep-09 13:35 
GeneralRe: foreach simple question Pin
JollyMansArt17-Sep-09 12:09
JollyMansArt17-Sep-09 12:09 
AnswerRe: foreach simple question Pin
Not Active17-Sep-09 13:26
mentorNot Active17-Sep-09 13:26 
Questiongood books for XML With windows c# Pin
santosh_anu17-Sep-09 9:44
santosh_anu17-Sep-09 9:44 
AnswerRe: good books for XML With windows c# Pin
Christian Graus17-Sep-09 10:29
protectorChristian Graus17-Sep-09 10:29 
AnswerRe: good books for XML With windows c# Pin
PIEBALDconsult17-Sep-09 10:45
mvePIEBALDconsult17-Sep-09 10:45 
Questionhow to add more buttons,images and logos in messagebox in c#. Pin
Ramesh Reddy1111117-Sep-09 7:32
Ramesh Reddy1111117-Sep-09 7:32 
AnswerRe: how to add more buttons,images and logos in messagebox in c#. PinPopular
EliottA17-Sep-09 7:55
EliottA17-Sep-09 7:55 
GeneralRe: how to add more buttons,images and logos in messagebox in c#. Pin
Ian Shlasko17-Sep-09 8:12
Ian Shlasko17-Sep-09 8:12 
GeneralRe: how to add more buttons,images and logos in messagebox in c#. Pin
Luc Pattyn17-Sep-09 8:22
sitebuilderLuc Pattyn17-Sep-09 8:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.