-2

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 "";
}
Kamil Budziewski
  • 22,699
  • 14
  • 85
  • 105
oozy
  • 23
  • 1
  • 5
  • Do you always have this kind of format? So always "CRM:*" t the end of a string where you want the number after `CRM:`? There are many different ways of how to solve this, so can you please add more examples on how your string could look like? – Kevin Brechbühl Mar 13 '14 at 07:48
  • yes i have this number after the crm i need the num by function in c# that bring my string answer – oozy Mar 13 '14 at 07:51

2 Answers2

0

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;
        }
    }
}
Alexander
  • 420
  • 1
  • 5
  • 17
0

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);
}
Kevin Brechbühl
  • 4,717
  • 3
  • 24
  • 47