I have a line item like :
//FirstString/Second[001]/LastString
I need to replace [001] to [002] using Xpath.
After replacement the line item should look like :
//FirstString/Second[002]/LastString
I tried this in C# as follows :
if (xpath.Contains("/Second") && xpath.Contains("["))
{
xpath = xpath.Remove(xpath.IndexOf("[")).Trim();
xpath = xpath.Replace("Second", "Second[002]");
}
But it is not working properly.
The result that I am getting : //FirstString/Second[002]
Instead of //FirstString/Second[002]/LastString
Any thoughts?
Thanks in Advance.
Regex solution: