using System; using System.Text.RegularExpressions; public class MainClass { public static void Main() { string x = "Once Upon A Time In America"; Regex m = new Regex("( )"); foreach (string ss in m.Split(x)) { Console.WriteLine(ss); } } }
Author: coder
Single spaces, using ()
using System; using System.Text.RegularExpressions; public class MainClass { public static void Main() { string x = "Once Upon A Time In America"; Regex m = new Regex("( )"); foreach (string ss in m.Split(x)) { Console.WriteLine(ss); } } }
Multiple spaces, using “[s]+”
using System; using System.Text.RegularExpressions; public class MainClass { public static void Main() { string v = "Once Upon A Time In America"; Regex o = new Regex(@"[s]+"); foreach (string ss in o.Split(v)) { Console.WriteLine(ss); } } }
Single space split
using System; using System.Text.RegularExpressions; public class MainClass { public static void Main() { string u = "Once Upon A Time In America"; Regex p = new Regex(" "); foreach (string ss in p.Split(u)) { if (ss.Length > 0) Console.WriteLine(ss); } } }
Multiple different delimiters
using System; using System.Text.RegularExpressions; public class MainClass { public static void Main() { string t = "Once,Upon:A/TimeIn'America"; Regex q = new Regex(@" |,|:|/||'"); foreach (string ss in q.Split(t)) { Console.WriteLine(ss); } } }
Open a SubKey in Registry
using System; using Microsoft.Win32; class MainClass { public static void SearchSubKeys(RegistryKey root, String searchKey) { foreach (string keyname in root.GetSubKeyNames()) { try { using (RegistryKey key = root.OpenSubKey(keyname)) { if (keyname == searchKey) PrintKeyValues(key); SearchSubKeys(key, searchKey); } } catch (System.Security.SecurityException) { } } } public static void PrintKeyValues(RegistryKey key) { Console.WriteLine("Registry key found : {0} contains {1} values", key.Name, key.ValueCount); foreach (string valuename in key.GetValueNames()) { if (key.GetValue(valuename) is String) { Console.WriteLine(" Value : {0} = {1}", valuename, key.GetValue(valuename)); } } } public static void Main(String[] args) { if (args.Length > 0) { using (RegistryKey root = Registry.CurrentUser) { SearchSubKeys(root, args[0]); } } } }
Get the Registry key found for CurrentUser
using System; using Microsoft.Win32; class MainClass { public static void SearchSubKeys(RegistryKey root, String searchKey) { foreach (string keyname in root.GetSubKeyNames()) { try { using (RegistryKey key = root.OpenSubKey(keyname)) { if (keyname == searchKey) PrintKeyValues(key); SearchSubKeys(key, searchKey); } } catch (System.Security.SecurityException) { } } } public static void PrintKeyValues(RegistryKey key) { Console.WriteLine("Registry key found : {0} contains {1} values", key.Name, key.ValueCount); foreach (string valuename in key.GetValueNames()) { if (key.GetValue(valuename) is String) { Console.WriteLine(" Value : {0} = {1}", valuename, key.GetValue(valuename)); } } } public static void Main(String[] args) { if (args.Length > 0) { using (RegistryKey root = Registry.CurrentUser) { SearchSubKeys(root, args[0]); } } } }