How to wrap a long string to specified number of characters in asp.net and C# ?

In some occasions we have a long string in our hand and we have only small space to display it, then we need to wrap our string to a specified number of characters so that it will fit in the space we have. Here is a simple c-sharp code for wrapping a string to a number of characters.

Suppose we have a string like this “Hai,this is a long string and I want it to be wrapped up to 30 characters”
after wrapping up it will be like this “Hai, this is a long string and …”

Target is the string to be wrapped
Index is the number of characters
DotCount is the number of dots attached to the string

Cheers

Leave a Reply

Your email address will not be published. Required fields are marked *