Question

hi i want to get just the Crm and the number in the line tenx

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

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

    return "";
}
Was it helpful?

Solution

It is a little bit unclear what you want. If you always have "CRM" in the subject, then you could do it like following:

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

OTHER TIPS

I would go with this, because Substring() is the fastest way:

public string GetCrmSubjectNum(string emailSubject)
{
    return emailSubject.Substring(emailSubject.IndexOf("CRM:", StringComparison.Ordinal) + "CRM:".Length);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top