如何拆分试用c#

时间:2014-03-13 07:43:20

标签: c# dynamics-crm-2011 crm dynamics-crm-online

嗨我想得到Crm和行中的数字 TENX

string emailsubject = "Email Test 2 CRM:0276002";

public string GetCrmSubjectNum()
{
    string final = //;

    return "";
}

2 个答案:

答案 0 :(得分:0)

有点不清楚你想要什么。 如果你总是有" CRM"在这个主题中,你可以这样做:

using System;

   namespace ConsoleApplication1
   {
    class Program
    {


        static void Main(string[] args)
        {
            string emailsubject = "Email Test 2 CRM:0276002";

            emailsubject = GetCrmSubjectNum(emailsubject);

            Console.WriteLine(emailsubject);

            Console.Read();
        }



        public static string GetCrmSubjectNum(string emailsubject)
        {
           emailsubject = emailsubject.Remove(0, emailsubject.IndexOf("CRM"));

            return emailsubject;
        }
    }
}

答案 1 :(得分:0)

我会选择这个,因为Substring()是最快的方式:

public string GetCrmSubjectNum(string emailSubject)
{
    return emailSubject.Substring(emailSubject.IndexOf("CRM:", StringComparison.Ordinal) + "CRM:".Length);
}