var str = "123,abc,AAA,a12,我,,";
string LogisticsNo = Console.ReadLine();
Regex reg = new Regex("([^,]*,){6}");
bool match = reg.IsMatch(LogisticsNo);
Console.WriteLine("匹配结果为:");
Console.WriteLine(match);
var result = LogisticsNo.Count(c => c == ',') == 6;
Console.WriteLine("统计逗号的结果为:");
Console.WriteLine(result);
Console.ReadKey();
正则匹配的搜索词为:([^,]*,){6}
结果如图所示,如果有你不满意的地方你可以参考:
https://msdn.microsoft.com/zh-cn/library/az24scfc%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396
自己修改
不用正则还方便些:
if(str.Count(x => x == ',') == 6)