// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Linq; using System.Text.RegularExpressions; namespace E { public class Program { private static int Count1(string s) { return s.Substring(0, 5).Count(x => Char.IsDigit(x)); } private static int Count2(string s) { return Regex.Match(s, @"(%+)(\d+)(%+)").Groups[2].Value.Length; } private static void Test(string s) { Console.WriteLine(s); Console.WriteLine(Count1(s)); Console.WriteLine(Count2(s)); } public static void Main(string[] args) { Test("%%2%%"); Test("%%51%%"); Test("%%197%%"); Console.ReadKey(); } } }