Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
newstring vs regex
//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; using System.Diagnostics; namespace Rextester { public class Program { public static void Main(string[] args) { //Your code goes here var x = "+1 (403) 555-1234"; Console.WriteLine(x); var y = GetNumbers(x); var z = GetNumbersRegex(x); Console.WriteLine(y); Console.WriteLine(z); } private static string GetNumbers(string input) { var timer = new Stopwatch(); timer.Start(); var result = new string(input.Where(c => char.IsDigit(c)).ToArray()); timer.Stop(); Console.WriteLine("Strip milliseconds: {0}", timer.ElapsedMilliseconds); return result; } private static string GetNumbersRegex(string input){ var timer = new Stopwatch(); timer.Start(); var result = Regex.Replace(input, "[^0-9]", ""); timer.Stop(); Console.WriteLine("Regex milliseconds: {0}", timer.ElapsedMilliseconds); return result; } } }
run
|
edit
|
history
|
help
0
Main 5.4
c# abstract
Hello-Heath-World
error2
Student Cables
Xamarin
c# kare çizimi
little problem
Find Max Number Of Occurences in an int array
List Array