truncate to nearest word

  • Thread starter Thread starter John A Grandy
  • Start date Start date
J

John A Grandy

i have written code to do the following task ...

* truncate a string to the nearest word so that the result string is less
than a certain length

.... but i am wondering the if .net class lib has built-in functionality to
do this and similar tasks ... ?
 
Hi John,

You'd think so - two other people have wanted the same routine in the last
month.- but string handling for text editing is only so good.

It's there in drawing terms - DrawString can fit a string within a given
rectangle, splitting the text as required.

You can fiddle it using a RichTextBox- use a fixed-width font and set the
rtb width so big. Then assign your string to the Text property and read the
result back out from the Lines() array.

But simple plain, string routines ? Nope!

What else did you have in mind?

Regards,
Fergus
 
John

When I see your question I don't know why but I have to think on the "Trim"
function.

It removes the spaces before and after a string.

Cor
 
Hi Fergus.

I am trying to fit within a rectangle ... but some lines need to wrap (to 2
or 3 lines) and some lines of text need to strictly truncate.

Typical addresee block that needs to fit in the see-through window of an
envelope. I wrote all the code to do it, but it was completely custom code.
I thought maybe something useful was built-into the class lib.
 
Back
Top