Hello;
Suppose I have a string like:
"Ministry Of Labour and Employment"
I need to split string after 20 characters, then sub strings are "Ministry Of Labour a" and "nd Employment" . How can I convert it in "Ministry Of Labour" and "and Employment"
Thanks in advance.

Raghav JhavarPosted Dec 16, 2015, 4:47 AM
Are you sure? I just re-tested my code, it gives me proper results.
Here is evidence: http://prntscr.com/9esafc
Akhil KumarPosted Jan 7, 2016, 2:01 AM
Sripal AmballaPosted Dec 30, 2015, 10:39 AM
string[] strArr = s.Split(' ');
int ires = 0;
string strText = "";
foreach (string str in strArr)
{
ires += str.Length;
if (ires <= 20)
{
strText += " " + str;
}
}
strText = strText.Trim(' ');
Console.WriteLine(strText);
MahaPosted Dec 17, 2015, 4:06 AM
MatthiasPosted Dec 14, 2015, 8:16 AM
char c = temp.ElementAt(number++);
if (c == ' ') break;
neu = neu.Substring(0, neu.Length-1);
}
Rajesh SinghPosted Dec 14, 2015, 7:11 AM
Francis SusaimichaelPosted Dec 14, 2015, 7:09 AM
Raja TPosted Dec 14, 2015, 7:03 AM
Ankit ShuklaPosted Dec 14, 2015, 6:40 AM
Ankit ShuklaPosted Dec 14, 2015, 6:38 AM
MatthiasPosted Dec 13, 2015, 6:44 AM
string s = "this is only some example okay";
char[] temp = s.ToCharArray();
string neu = s.Substring(0, number);
while (true)
{
char c = temp.ElementAt(number++);
neu += c;
if (c == ' ') break;
}
Raghav JhavarPosted Dec 13, 2015, 5:23 AM
MatthiasPosted Dec 13, 2015, 5:20 AM
Raghav JhavarPosted Dec 13, 2015, 2:51 AM
using System;
Francis SusaimichaelPosted Dec 11, 2015, 7:14 AM
Ankur MistryPosted Dec 11, 2015, 7:01 AM
Venkata SubbareddyPosted Dec 11, 2015, 6:50 AM
Please note that additional code might be required to gracefully handle edge cases (
Try thisnullor empty input string,chunkSize == 0, input string length not divisible bychunkSize, etc.). The original question doesn't specify any requirements for these edge cases and in real life the requirements might vary so they are out of scope of this answer.