开发者

Allocating data in Array with same length string

I am stuck in allocating data in array. for example i have 100 words in paragraph now i want to make array which contain 10 words in each array slot but not break words mean "Hello" in one slot would be "hel" and in second slot rest of word "lo".

Can anyone know how to implement it?

my paragraph look like

\r\n hi how are you\r\n whats going on

\r\n \r\n  Google Translate API for .NET 0.4 alpha

\r\n ¶\r\n\r\nDescription:\r\n\r\nProvides a simple, unofficial, .NET Framework API for using Google Ajax Language API service.\r\n\r\nFeature:\r\n

\r\n * tyle5\">Support all functions of Google Ajax Language API. \r\n

\r\n * CLS compatible. It can be used by any .NET languages (VB.NET, C++/CLI etc.) \r\n\r\nVersions: Google Search API for .NET comes in different versions for the various .NET frameworks. * .NET Framework 3.5 Client Profile.

\r\n * .NET Framework 2.0

\r\n * .NET Compact Framework 3.5

\r\n * Silverlight 3.0 \r\n\r\n

\r\n Example:\r\n\r\n string text = \"我喜欢跑步。\";\r\n

\r\n TranslateClient client = new TranslateClient(/* Enter the URL of your site here */);\r\n string translated = client.Translate(text, Language.ChineseSimplified, Language.English);\r\n Console.WriteLine(translated);\r\n // I like running. \r\n \r\n

\r\n

\r开发者_JAVA百科\n \r\n "


If I understood you correctly, you need something like this. If not, please let me know.

char separator = ' ';
int length = 10;
var splitted = paragraph.Split(separator);
List<string[]> arrays = new List<string[]>();
for (int i = 0; i < splitted.Length / length + 1; i++)
{
    arrays.Add(splitted.Where((x, y) => y >= i * length && y < (i + 1) * length)
        .Select( word => word + separator).ToArray());
}

foreach (var arr in arrays)
{
    foreach (var cell in arr)
    {
        Console.Write(cell);
    }
    Console.WriteLine();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜