How can I speed up this method which removes text from a string?
c#, performance, text
Solution
You could try parallelism since it doesn't look like you need a synchronous treatment. A parallel foreach with PLINQ would do the trick.
But if you cannot wait until VS2010 is officially out, you could try Poor Man's Parallel.ForEach Iterator by Emre Aydinceren
Problem
I wrote the following method to remove the namespace in brackets from strings. I would like to make this as fast as possible. Is there a way to speed up the following code? ``` using System; namespace TestRemoveFast { class Program { static void Main(string[] args) { string[] tests = { "{http://company.com/Services/Types}ModifiedAt", "{http://company.com/Services/Types}CreatedAt" }; foreach (var test in tests) { Console.WriteLine(Clean(test)); } Console.ReadLine(); } static string Clean(string line) { int pos = line.IndexOf('}'); if (pos > 0) return line.Substring(pos + 1, line.Length - pos - 1); else return line; } } } ```