Click here to Skip to main content
15,868,016 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!
 
Share this answer
 
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

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