I have the following code:
var hyphens = myString.Split('-');
topTitle = hyphens[0].Replace("_", " ");
subTitle = hyphens[1].Replace("_", " ");
This is working but if myString does not have two words with a hyphen between them I get an error. How can I make it such that if the myString contains only one word then topTitle gets that word and subTitle gets “n/a”?
You could use Regex, but changing your code a little bit helps also.
Just check the
Length, if it’s less than one show them “n/a” like you want.