加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 如何加快从字符串中删除文本的方法?

发布时间:2020-12-15 04:17:56 所属栏目:百科 来源:网络整理
导读:我编写了以下方法来从字符串中删除括号中的命名空间. 我想尽快做到这一点. 有没有办法加快以下代码? using System;namespace TestRemoveFast{ class Program { static void Main(string[] args) { string[] tests = { "{http://company.com/Services/Types}
我编写了以下方法来从字符串中删除括号中的命名空间.

我想尽快做到这一点.

有没有办法加快以下代码?

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;
        }
    }
}

解决方法

您可以尝试并行性,因为它看起来不像您需要同步处理.与PLINQ平行的foreach可以解决这个问题.

但如果你不能等到VS2010正式退出,你可以试试Poor Man’s Parallel.ForEach Iterator by Emre Aydinceren

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读