Simple recursive function for string folding in C#

Here is the sample function of string folding in c#. I just tried bind the body content of a mail in to a label box. For that I need to folding the string content. I have created a method to do this string folding as follows,

if (lblBody.Text.Length > 150)
{
lblBody.Text = lblbodystring(lblBody.Text,150);
}

//Simple recursive function for string folding.
private string lblbodystring(string bodyString, int Length)
{
string retVal = "";
if (bodyString.Length > Length)
{
retVal = bodyString.Substring(0, Length);
retVal = retVal + Environment.NewLine;
retVal = retVal + lblbodystring(bodyString.Substring(Length));
}
else
{
retVal = retVal + Environment.NewLine;
retVal = retVal + bodyString;
}
return retVal;
}


The thing is that we can use textbox with multiline attribute for this kind of process :). But I have used in label. So...

...S.VinothkumaR.

No comments: