in reply to truncating a line

Use length to find the length, and then substr to chop it.

BTW a tip. It works slightly more smoothly if you only chop and add the dots if the string is over 20 characters.

Replies are listed 'Best First'.
Re: Re: truncating a line
by fireartist (Chaplain) on Jul 02, 2003 at 09:41 UTC
    BTW a tip. It works slightly more smoothly if you only chop and add the dots if the string is over 20 characters.
    What exactly do you mean by this?
    is there a technical reason,
    or because it cuts a word in half with that particular string,
    or in your experience 20 chars is best to still leave the string reasonably understandable?

    Cheers,
    fireartist
      Because truncating and adding 3 dots leaves the length of the string at 20 chars. Why bother truncating and indicating a continuation unless you are going to wind up with a shorter string for the loss of information?

      Trust me. This is a detail that users tend to notice.

        ah, I get you now. I had read a completely different meaning into what you originally wrote.

        You were saying to check that the string actually is more than 20 characters before chopping it to 20 chars and adding the dots.

        I had thought you were saying: choose a length longer than 20, because it'll read better for some reason.

        Well, glad that's cleared up then!