I am new to C#, but I have a requirement to cut the strings to be <= 80 characters AND they must keep the words integrity (without cutting them)
Examples
Before:
I have a requirenment to cut the strings to be <= 80 characters AND must keep the words without cutting them (length=108)
After:
I have a requirenment to cut the strings to be <= 80 characters AND must keep (length=77)
Before:
requirenment to cut the strings to be <= 80 characters AND must keep the words without cutting them (length=99)
After:
requirenment to cut the strings to be <= 80 characters AND must keep the words (length=78)
Before:
I have a requirenment the strings to be <= 80 characters AND must keep the words without cutting them (length=101)
After:
I have a requirenment the strings to be <= 80 characters AND must keep the words (length=80)
I want to use the RegEx, but I don't know anything about the regex. It would be a hassle to to the else-if's for this. I would appreciate if you could point me to the right article which I could use to create this expression.
this is my function that I want to cut to one line:
public String cutTitleto80(String s){
String[] words = Regex.Split(s, "\\s+");
String finalResult = "";
foreach (String word in words)
{
String tmp = finalResult + " " + word;
if (tmp.Length > 80)
{
return finalResult;
}
finalResult = tmp;
}
return finalResult;
}