The following function will do what I believe you want. Note that I used a
parameter to specify the maximum number of characters before a space, just
in case you decide to change it from 40.
public string EnsureSpaces(string target, int maxChars)
{
StringBuilder result = new StringBuilder();
int charCount = 0;
for (int i = 0; i < target.Length; i++)
{
if (target[i] != ' ') charCount++;
else charCount = 0;
if (charCount >= maxChars) result.Append(' ');
result.Append(target[i]);
}
return result.ToString();
}
--
HTH,
Kevin Spencer
Microsoft MVP
Software Composer
http://unclechutney.blogspot.com
A watched clock never boils.
<hk**********@hotmail.comwrote in message
news:11*********************@e3g2000cwe.googlegrou ps.com...
>i have an application that will take user input from a text box and
write it
to an access database. i need to make sure that if they ever enter a
single
line of text that it has at least 1 space for every 40 characters.
so before i write the info to the database i have to make sure there is
no
lines of text that are longer than 40 characters without a space, and
if
there are insert a space at the 41st character. is that as hard as it
sounds?
hk**********@hotmail.com