Click here to Skip to main content
15,902,447 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Ok I don't feel like the question is self-explanatory so I will explain it.
I'm making a program that requires relocating the data, but it reads a line one by one so I need to store things to replace and to replace it with in a array.
Lets say I need to replace the string
"test"
with
"test2"
well my array would be set up like this:
C#
string[] arr = new string[10];
arr[1] = "test";
arr[2] = "test2";


That would be the setup.
Here's my code for this:
C#
string text = kek.Text;

for (int idx = 0; idx < reloc.Length; idx++)
{
    text = Regex.Replace(text, reloc[idx], reloc[idx + 1]);
}
return text;


I was wondering how would I do this correctly as the error I'm getting right now is:
"Value Cannot be Null Parameter Name Pattern"

What I have tried:

Rewriting my method.
Adjusting with simple math.
Posted
Updated 16-Nov-17 18:17pm
Comments
Bryian Tan 17-Nov-17 0:00am    
The array start with 0. I'm guess reloc[0] is null because the array with dummy data start from 1 (arr[1] = "test"; again assuming arr is reloc)? I'm just guessing based on what being presented here
The Chaotic Void 17-Nov-17 0:04am    
Already tried that before but yes that was the idea
Karthik_Mahalingam 17-Nov-17 0:11am    
what is your input and expected output ?

1 solution

Here is an example based on what you had provided. Assuming there are only two dummy value in the reloc array. But the loop is trying to loop 10 times (length of the array). The code will complaint because it try to retrieve the value from reloc[2], reloc[3], ...which is not available. Again that just my assumption based on what being presented here.

C# Online Compiler | .NET Fiddle[^]
 
Share this answer
 

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