Note that there are some explanatory texts on larger screens.

plurals
  1. POCut the string to be <= 80 characters AND must keep the words without cutting them
    text
    copied!<p>I am new to C#, but I have a requirement to cut the strings to be &lt;= 80 characters AND they must keep the words integrity (without cutting them)</p> <p><code>Examples</code></p> <p><code>Before:</code> I have a requirenment to cut the strings to be &lt;= 80 characters AND must keep the words without cutting them (length=108)<br> <code>After:</code> I have a requirenment to cut the strings to be &lt;= 80 characters AND must keep (length=77)</p> <p><code>Before:</code> requirenment to cut the strings to be &lt;= 80 characters AND must keep the words without cutting them (length=99)<br> <code>After:</code> requirenment to cut the strings to be &lt;= 80 characters AND must keep the words (length=78)</p> <p><code>Before:</code> I have a requirenment the strings to be &lt;= 80 characters AND must keep the words without cutting them (length=101)<br> <code>After:</code> I have a requirenment the strings to be &lt;= 80 characters AND must keep the words (length=80)</p> <p>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.</p> <p>this is my function that I want to cut to one line:</p> <pre><code>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 &gt; 80) { return finalResult; } finalResult = tmp; } return finalResult; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload