?? Using String.Format() for a MAXIMUM Length ??

A

Alan Foxmore

Hello all,

Is it possible to use String.Format() to specify a maximum length for a
formatted item? For example, let's say I have:

String.Format("{0}", "FREDDY");

How can I specify that the result of the formatting should be a string
no longer than, say, 3 characters? I know I can easily specify the
minimum length, but I am producing a report with columns. I need to
specify the maximum length, truncating whatever does not fit.

Is it possible without resorting to a custom formatter?

Please note that I want to do this with String.Format() rather than
something like, myString.Substring(0,4);


Thanks.
 
P

Paul E Collins

Alan said:
Is it possible to use String.Format() to specify a
maximum length for a formatted item?

No (except in certain limited cases, like decimal places of a number).
You'd have to use String.Substring or equivalent.

Eq.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top