c# - How do I extract and replace a substring with a different value -
i have following string: "using following data [environmentvar][testaccount] status connected"
what want replace [environmentvar][testaccount] data retrieved xml file. need first extract [environmentvar][testaccount] own string , have method query xml, furthermore need once i've retrieved value replace original string.
there's curve ball, structure wont be:
[environmentvar][testaccount]
it might have "nodes" like:
[systemtest][environmentvar][testaccount]
or
[region][systemtest][environmentvar][testaccount]
as long can extract pattern original string can grab data it. mentioned above need able replace "[systemtest][environmentvar][testaccount]" data i've retrieved. example might simple "ukuser" gets returned new string end being "using following data ukuser status connected"
any guidance appreciated, i'm sure there many ways of doing this.
update
heres , example
string myquery = "using following data [systemtest][environmentvar][testaccount]"; string xmlquery = retrievexmlquery(myquery); //so want xmlquery "[systemtest][environmentvar][testaccount]" //xml query gets executed string xmlresult = retrievexmlvalue(xmlquery); //xmlresult "ukuser" //now want take string "using following data [systemtest][environmentvar][testaccount]" , replace nodes ukuser becomes "using following data ukuser" //remember number of nodes , sequence wont same...
in case want replace "extra nodes" too, when exist:
string input = "using following data [environmentvar][testaccount] status connected"; string newdata = "ukuser"; string output = regex.replace(input, @"(\[.*\])", newdata); console.writeline(output); // using following data ukuser status connected
Comments
Post a Comment