var myNew = myRegex1.Split(strTargetString);
if ((myNew[1].Trim()).Length > 12)
{
myNew[1]= (myNew[1].Substring(0, 9))+"..";
} }
_model.Add(new ScoresModel()
{
NameTeam1 = (myNew[1].Trim()),
ScoreTeam1 = Convert.ToInt32(myNew[2].Trim()),
NameTeam2 = (myNew[3].Trim()),
ScoreTeam2 = Convert.ToInt32(myNew[4].Trim()),
Round = (myNew[5].Trim()).Substring(1, myNew[5].Length - 2),
URL = item.ItemLink
});
以上是我的规范。将字符串分成 5 部分后。我想对第一个拆分的字符串进行检查,它的长度是否大于 12。如果是,则将其修剪为 10 个字符并在字符串后面附加“..”(两个点)。* 但在修剪代码后,myNew[1]、myNew[2]、myNew[3]、myNew[4]、myNew[5] 上的以下方法出现错误。* 错误是The name myNew does not exist in current context.
_model.Add(new ScoresModel()
{
NameTeam1 = (myNew[1].Trim()),
ScoreTeam1 = Convert.ToInt32(myNew[2].Trim()),
NameTeam2 = (myNew[3].Trim()),
ScoreTeam2 = Convert.ToInt32(myNew[4].Trim()),
Round = (myNew[5].Trim()).Substring(1, myNew[5].Length - 2),
URL = item.ItemLink
});