locked
Extract A string RRS feed

  • Question

  • User-1499457942 posted

    Hi

      I have below code . In this i want to extract all characters after first _ means it should return Test_1.xlsx

    http://localhost:1010/Docs/d7acf30c-5f27-433c-b73f-43a651a7f5c3_Test_1.xlsx

    Thanks

    Thursday, January 3, 2019 7:33 AM

All replies

  • User-1716253493 posted
    string str = "http://localhost:1010/Docs/d7acf30c-5f27-433c-b73f-43a651a7f5c3_Test_1.xlsx";
    string result = str.Replace(str.Split('_').First() + '_', "");

    Thursday, January 3, 2019 9:00 AM
  • User-271186128 posted

    Hi JagjitSingh,

    In this i want to extract all characters after first _ means it should return Test_1.xlsx

    http://localhost:1010/Docs/d7acf30c-5f27-433c-b73f-43a651a7f5c3_Test_1.xlsx

    You could also get the index of the first '_' , then using String.Substring method to obtain a substring.

    Code as below:

                string str = "http://localhost:1010/Docs/d7acf30c-5f27-433c-b73f-43a651a7f5c3_Test_1.xlsx";
                string result = str.Substring(str.IndexOf('_') + 1);

    Best regards,
    Dillion

    Friday, January 4, 2019 1:40 AM