There could be a number of ways to do this.
You could just do this
<br />
if text.length > 0 && text.Contains(',')<br />
string _str = text.Remove(text.LastIndexOf(','));
Another approach could be to club the
if
statement in the same line
string _str = text.Length>0 && text.Contains(',')?text.Remove(text.LastIndexOf(',')):String.Empty;