Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace Testing_Console
- {
- class Program
- {
- static void Main(string[] args)
- {
- // Part 1
- var watch = new System.Diagnostics.Stopwatch();
- var length = 0;
- watch.Start();
- length = GetLineLength1("- Ivandro Ismael\r\n- Gomes Jao"); // Split
- watch.Stop();
- Console.WriteLine(watch.Elapsed + " " + length);
- watch.Reset();
- watch.Start();
- length = GetLineLength2("- Ivandro Ismael\r\n- Gomes Jao"); // Replace
- watch.Stop();
- Console.WriteLine(watch.Elapsed + " " + length);
- Console.ReadLine();
- }
- static char[] newLineChars = Environment.NewLine.ToArray();
- static int GetLineLength1(string line)
- {
- return line.Split(newLineChars, StringSplitOptions.RemoveEmptyEntries).Length;
- }
- static int GetLineLength2(string line)
- {
- return line.Length - line.Replace(Environment.NewLine, string.Empty).Length;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement