What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 133 Stack Exchange communities.

Many question list views have ~188 characters of the question body text. However, this cut-off point may be in the middle of an entity such as >, sometimes resulting in broken summaries like

... template<typename T&gt

IMHO the cut-off point should be at a word boundary or at least a displayable character boundary, not just at a byte offset.

share|improve this question

4 Answers 4

Good idea, so I'll just greedily take up to 200 characters, as many as I can, until I hit a space:

var r = new Regex(@".{0,200}\s", 
    RegexOptions.Compiled | RegexOptions.Singleline);
return r.Match(body) + separator;
share|improve this answer

I think this is a good point - a lot of work has obviously gone in to making these sites look as good as they do, and this does, in however minor a way, detract from this. I can't imagine the code fix to at least prevent breaking in the middle of an entity would be that complex.

share|improve this answer

Something like this might work (without knowing the actual schema). It may be worth pre-computing the fragment, too.

var question = new Question { Text = text, ... }
var stringBits = text.Split(' ');
if (stringBits[0].Length < MAX_SNIPPET_LENGTH)
{
    var builder = new StringBuilder(stringBits[0]);
    for (int i = 1; i < stringBits.Length; ++i )
    {
        if (builder.Length + stringBits[i].Length < MAX_SNIPPET_LENGTH)
        {
            builder.AppendFormat( " {0}", stringBits[i] );
        }
        else
        {
            break;
        }
    }
    question.Snippet = builder.ToString();
}
else
{
    question.Snippet = stringBits[0].Substring(0, MAX_SNIPPET_LENGTH);
}
share|improve this answer
    
True -- I'll suggest an alternative. –  tvanfosson Jul 4 '09 at 19:07
    
Deleted my old comment. I've never done any C# before but reading this as pseudocode seems to match that word boundary suggestion of mine. –  laalto Jul 4 '09 at 19:28

I think for the most part this is not a great big deal and it will end up being a larger time actually developing the fix than the time or energy saved in having to click the actual article to see the true text.

share|improve this answer
3  
Agree it's more a visual glitch than a problem. But small glitches contribute to the feeling how well or bad the site is looked after –  laalto Jul 4 '09 at 10:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .