I wouldn't be happy with the existing answers because they don't handle the "Allowed formats" prefix, which ought to vary also:
public static string FormatAllowed(string allowedFormats)
{
var formats = allowedFormats.Split(new[] {'|'},
StringSplitOptions.RemoveEmptyEntries);
return formats.Length == 0 ? "No formats allowed" :
formats.Length == 1 ? "Allowed format is \"" + formats[0] + "\"" :
string.Join("",
formats.Select(
(format, index) =>
(index == 0 ? "Allowed formats are " :
(index == formats.Length - 1 ? " and " : ", ")) +
"\"" + format + "\"")
.ToArray());
}
Test it like this:
static void Check(string formats, string expected)
{
var result = FormatAllowed(formats);
Console.WriteLine(result);
Debug.Assert(result == expected);
}
static void Main(string[] args)
{
Check("", "No formats allowed");
Check(".jpg", "Allowed format is \".jpg\"");
Check(".jpg|.png", "Allowed formats are \".jpg\" and \".png\"");
Check(".jpg|.gif|.png", "Allowed formats are \".jpg\", \".gif\" and \".png\"");
Check(".jpg|.gif|.png|.txt", "Allowed formats are \".jpg\", \".gif\", \".png\" and \".txt\"");
}