Click here to Skip to main content
15,064,915 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am stuck at a part where i have to use Replace function multiple times simultaneously c# win. form.

Example
Raw Data
myarray[0] = "A";
myarray[1] = "B";
myarray[2] = "C";


Now, i want to replace all A with B and all B with A and result should be like below

myarray[0] = "B";
myarray[1] = "A";
myarray[2] = "C";



[Note:the above is just an example and in real, my array is filled with all possible characters so please don't suggest replacing it with something else.]

I cannot give you the code as i have no idea how to do this. Can anybody help me by providing a code snippet?





Thanks in advance
Posted

1 solution

As you are talking about an array you have no actual problem!
All you need is run a simple loop over all the array elements and replace them according to your rules.
All element will be handled once in the loop so you will get the exact result you are looking for!
   
Comments
agent_kruger 24-Dec-14 3:31am
   
cant use loop because of performance issue
Kornfeld Eliyahu Peter 24-Dec-14 3:34am
   
What performance?
agent_kruger 24-Dec-14 3:35am
   
i have huge number of array so if i use looping my performance will go down
Kornfeld Eliyahu Peter 24-Dec-14 3:37am
   
Who told you? Who told you you have to use a non-parallel loop? How much is huge? 20 million? More?
agent_kruger 24-Dec-14 3:38am
   
nope it is just 70,000 but for every element i would have to run 70,000 again and again and the number would go beyond imagination
Kornfeld Eliyahu Peter 24-Dec-14 3:42am
   
Why 'again and again'?! The whole idea is to run once and handle every element once! That what will prevent to replace A to B and than back to A...
agent_kruger 24-Dec-14 3:45am
   
the process i am doing is to replace every Key in my dictionary with its value but with your looping i have to loop it 70,000 times to find just 1 element
Kornfeld Eliyahu Peter 24-Dec-14 3:47am
   
You didn't talked about it at all...You have to refine your question to get more specific answers...
agent_kruger 24-Dec-14 3:51am
   
no sir, i just mentioned that i have to replace 1st value with other and the other value with the 1st one. But if you are suggesting loop then comes the detail that i have to do this with every element in my dictonary
Kornfeld Eliyahu Peter 24-Dec-14 3:55am
   
Maybe giving us a real sample can help...
agent_kruger 24-Dec-14 3:51am
   
still thanks for taking interest in my question

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900