By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,504 Members | 1,190 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,504 IT Pros & Developers. It's quick & easy.

truncate to nearest word

P: n/a
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 ... ?

Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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

Nov 20 '05 #2

P: n/a
Cor
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
* 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 ... ?

Nov 20 '05 #3

P: n/a
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.

"Fergus Cooney" <fi*****@post.com> wrote in message
news:e8**************@tk2msftngp13.phx.gbl...
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

Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.