Alan Alan - 1 year ago 82
C# Question

How can I display the first word of a series of words that ends with a semicolon?

My application gets phrases from a database. These strings can look like this:

house; home; residence

How can I format these strings so that the resulting output looks like:


In other words if there's a semicolon immediately following the first word I would like to just include from the start up to the end of the semicolon and if no semicolon then just include the first word.

Answer Source
string str = "house; home; residence";
string firstWord = str.Split(';').FirstOrDefault();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download