这听起来可能很愚蠢,但是如果字符串看起来像这样"string with white-space after last character "
,我怎么能找到字符串中的最后一个字符索引,如果它是一致的并且只有 1 没问题,但有时它可能是 2 或 3 个空格
编辑: 我无法将当前字符串修剪为新字符串,因为最后一个字符的索引不正确。我想保持字符串原样
这就是我得到的原因和结果
string description = "Lorem Ipsum is simply dummy text of the printing and typesetting indu. Lorem Ipsum has ben indusry s tandard dummy text ever since the 1500s.";
description = Regex.Replace(description, @"(?></?\w+)(?>(?:[^>'""]+|'[^']*'|""[^""]*"")*)>", String.Empty);
if (description.Count() > 101)
{
description = description.Substring(0, 101);
if (description.GetLast() != " ")
{
description = description.Substring(0, description.LastIndexOf(" ", 101)) + "...";
}
else
{
//here is should find the last character no mather how many whitespaces
description = description.Substring(0, description.Length - 1) + "...";
}
}