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 Jhavar57 reputationPosted Dec 15, 2015, 11:47 PM EST
Are you sure? I just re-tested my code, it gives me proper results.
Here is evidence: http://prntscr.com/9esafc
Raghav Jhavar57 reputationPosted Dec 13, 2015, 12:23 AM EST
Matthias24 reputationPosted Dec 14, 2015, 3:16 AM EST
char c = temp.ElementAt(number++);
if (c == ' ') break;
neu = neu.Substring(0, neu.Length-1);
}
Venkata SubbareddyRank #2,083 · 691 reputationPosted Dec 11, 2015, 1:50 AM EST
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.Ankur MistryRank #86 · 23.9K reputationPosted Dec 11, 2015, 2:01 AM EST
Francis SusaimichaelRank #466 · 5.4K reputationPosted Dec 11, 2015, 2:14 AM EST
Raghav Jhavar57 reputationPosted Dec 12, 2015, 9:51 PM EST
using System;
Matthias24 reputationPosted Dec 13, 2015, 12:20 AM EST
Matthias24 reputationPosted Dec 13, 2015, 1:44 AM EST
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;
}
Ankit ShuklaRank #2,120 · 672 reputationPosted Dec 14, 2015, 1:38 AM EST
Ankit ShuklaRank #2,120 · 672 reputationPosted Dec 14, 2015, 1:40 AM EST
Raja TRank #685 · 3.5K reputationPosted Dec 14, 2015, 2:03 AM EST
Francis SusaimichaelRank #466 · 5.4K reputationPosted Dec 14, 2015, 2:09 AM EST
Rajesh SinghRank #1,805 · 824 reputationPosted Dec 14, 2015, 2:11 AM EST
MahaRank #2,573 · 543 reputationPosted Dec 16, 2015, 11:06 PM EST
Sripal Amballa48 reputationPosted Dec 30, 2015, 5:39 AM EST
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);
Akhil Kumar18 reputationPosted Jan 6, 2016, 9:01 PM EST