Given the following values which I am reading from an XML file:
00B50578 00A41434 00B50578
And, given the following string:
string foo = "6F6F6F6F6F";
I’d like to somehow replace the characters which I am reading from the XML file with the characters in “foo”. However, I’d like to start replacing those characters after the “00” and only continue replacing those characters in such a way that it would be equal to the length of “foo”. So, if I had my way, the new values would be as follows:
006F6F6F 006F6F34 00B50578
I’ve tried a few ways of solving this issue, but to no avail.
Let’s say I read the XML values into an array called “arrXmlValues” I have written code that looks like this…
string foo = "6F6F6F6F6F";
string[] arrXmlValues = new String[] { xmlReader.GetAttribute("w:val") };
foreach (string r in arrXmlValues)
{
Console.WriteLine("Original value was : {0}", r);
StringBuilder sb = new StringBuilder(r);
sb.Remove(2, foo.Length);
sb.Insert(2, foo);
Console.WriteLine("New value is : {0}", sb);
Console.WriteLine("");
}
The caveat's here is the 8 digit blocks of hex values must remain as such. So, I can only replace 6 chars in each block at a time and whatever wasn't written to the fist block on the list must be written to the second block on the list but only if i have left to write based on the variable "foo"...
Certainly, open to new ways of accomplishing this and any ideas that you might offer. I am not a strong coder but my goal here is to solve this problem for a school project and also to learn.
I appreciate any help, guidance. Sample code to accomplish this goal would be great. Thank you!!!