locked
How to trim second special characters from a string RRS feed

  • Question

  • Hi All, 

    I am facing little bit problem to trim a string. Please help me

    I have below string and i want to trim from second special characters here

    eg : string name = "student_name_0_1_2_3";

    i need output like below. and i want to trim from second special character(_) onwards.

    "student_name"

    Please help me.

    Thanks in Advance

    Chandu

    Wednesday, July 4, 2018 6:58 AM

Answers

  • Regular expressions could help:
    string name = "Student_name_0_1_2_3";
    Match result = Regex.Match(name, @"\p{L}+_\p{L}+");
    
    Console.WriteLine(result.Value);
    
    
    wizend
    Wednesday, July 4, 2018 7:56 AM