How to remove unnecessary value from string

I have strJobProfile variable which value has AMRPM285P03 - Sr. Project Manager
from above string i wanted remove - Sr. Project Manager how can i do this

You can split the string or use regex


Trim removes blank space.
(0) keeps whats before the “-”
“-” is the charactetr your splitting on

Check out academy for learning about the basics:


string strJobProfile = "AMRPM285P03 - Sr. Project Manager";
string modifiedString = strJobProfile.Replace(" - Sr. Project Manager", "");

This will replace the specified text with an empty string and store the modified string in the modifiedString variable.