Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text.RegularExpressions;
- public class Folders
- {
- public static IEnumerable<string> FolderNames(string xml, char startingLetter)
- {
- List<string> result = new List<string>();
- char[] separator = {'"'};
- string[] wordsArray = xml.Split(separator, StringSplitOptions.RemoveEmptyEntries);
- for (int i = 0; i < wordsArray.Length-2; i++)
- {
- if (wordsArray[i].Contains("folder name=") && wordsArray[i+1].StartsWith($"{startingLetter}"))
- {
- result.Add(wordsArray[i + 1]);
- }
- }
- return result;
- }
- public static void Main(string[] args)
- {
- string xml =
- "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
- "<folder name=\"c\">" +
- "<folder name=\"program files\">" +
- "<folder name=\"uninstall information\" />" +
- "</folder>" +
- "<folder name=\"users\" />" +
- "</folder>";
- foreach (string name in Folders.FolderNames(xml, 'u'))
- Console.WriteLine(name);
- Console.ReadLine();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement