【发布时间】:2016-03-27 06:01:22
【问题描述】:
在我们的报告打印模板之一中有以下代码:
if (!string.IsNullOrEmpty(assetModel.Belongings))
{
description = string.Format("{0}{1}{2}",
description,
string.IsNullOrEmpty(description) ? "" : ", ",
assetModel.Belongings);
}
我想测试 Belongings 字段的第一个字符。如果它不是“,”,那么应该使用上面的代码,但如果它是“,”,代码应该是这样的:
if (!string.IsNullOrEmpty(assetModel.Belongings))
{
description = string.Format("{0}{1}{2}",
description,
string.IsNullOrEmpty(description) ? "" : "",
assetModel.Belongings);
}
请帮忙,我如何测试第一个字符的这个值?
【问题讨论】:
-
你可以使用String.StartsWith