Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Fórum ➡ Using Regex to insert "item" tags into the unique "list" tag of an XML data ♦
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; // aljodav // http://rextester.com/users/376 // in reply to MSDN thread // http://bit.ly/2fQafU4 namespace Rextester { public class Program { public static void Print(string xml){ Console.WriteLine("\n\n"+Regex.Replace(xml,"<item>","\n<item>")); } public static string AddItemToList(string xml,string item){ string pattern="(><)(?=/list>)"; string replacement="><item>"+item+"</item><"; return Regex.Replace(xml,pattern,replacement); } public static void Main(string[] args) { string xml="<data><id>54321</id><list></list></data>"; // load the whole data xml=AddItemToList(xml,"First"); xml=AddItemToList(xml,"Second"); xml=AddItemToList(xml,"Third"); xml=AddItemToList(xml,"Fourth"); xml=AddItemToList(xml,"Fifth"); Console.WriteLine(xml); Print(xml); // save to a file if needed Console.WriteLine("\n\nHello, world!"); } } }
run
|
edit
|
history
|
help
0
Sum Matrix Main Diagonal
example
sdcsadxsdf
UUEncode, UUDecode, XXEncode or XXDecode a string.
Code Challenege
C# - a method that accepts an indefinite number of parameters
uzyskanie daty poniedziałku
sroitureoit
Struct Ejemplo
Plt-D v.0.9.1