I have file containing string "CRef" 39 times in different Lines, what i need is to change every "CRef" to "CRef1", "CRef2",..... and so on.
For Example the Input:
<CrossReferenceSource Self="CRef" AppliedFormat="uf4">Depressed people are often dependent on others emotionally and seek reassurance in ways that distance others. They may often overvalue relationships.
<CrossReferenceSource Self="CRef" AppliedFormat="uf4" Hidden="false">The cognitive symptoms of depression interfere with work. Three ways in which depression may impair work performance are (1) interpersonal relationships (depressed people are seen as irritable, pessimistic, and withdrawn); (2) productivity
The Output Should be
<CrossReferenceSource Self="CRef1" AppliedFormat="uf4">Depressed people are often dependent on others emotionally and seek reassurance in ways that distance others. They may often overvalue relationships.
<CrossReferenceSource Self="CRef2" AppliedFormat="uf4" Hidden="false">The cognitive symptoms of depression interfere with work. Three ways in which depression may impair work performance are (1) interpersonal relationships (depressed people are seen as irritable, pessimistic, and withdrawn); (2) productivity
What i tried is to MatchCollection
for all "CRef" and foreach
loop on every match but the result was
<CrossReferenceSource Self="CRef12" AppliedFormat="uf4">Depressed people are often dependent on others emotionally and seek reassurance in ways that distance others. They may often overvalue relationships.
<CrossReferenceSource Self="CRef12" AppliedFormat="uf4" Hidden="false">The cognitive symptoms of depression interfere with work. Three ways in which depression may impair work performance are (1) interpersonal relationships (depressed people are seen as irritable, pessimistic, and withdrawn); (2) productivity
and so on.
This is a sample code of what i tried:
int Count = 1;
MatchCollection CRef = Regex.Matches(File, @"CRef");
foreach (var item in CRef)
{
string cross = Regex.Replace(item.ToString(), @"CRef", "CRef" + Count.ToString());
Count++;
final3 = final3.Replace(item.ToString(),cross);
}