Possible Duplicate:
Splitting a string into chunks of a certain size
Is there anyway to split a string for the every 714 character? this is due to the debug.writeline limitation in c#
Possible Duplicate:
Splitting a string into chunks of a certain size
Is there anyway to split a string for the every 714 character? this is due to the debug.writeline limitation in c#
Yes, I'd use Substring
:
string myString = "Some very long string you need to output.";
for(int i = 0; i < myString.length; i += 714) {
Debug.WriteLine(myString.Substring(i, Math.Min(714, myString.Length - i)));
}
Or, for a fancy one-liner:
foreach(var s in Regex.Matches(myString, ".{,714}")) Debug.WriteLine(s.Value);
You could use this code:
static IEnumerable<string> Split(string str, int chunkSize)
{
return Enumerable.Range(0, str.Length / chunkSize)
.Select(i => str.Substring(i * chunkSize, chunkSize));
}
From Splitting a string into chunks of a certain size
And make your own writeline method
Solved by using this
int chunkSize = 700;
int stringLength = str.Length;
for (int i = 0; i < stringLength; i += chunkSize)
{
if (i + chunkSize > stringLength) chunkSize = stringLength - i;
Debug.WriteLine(str.Substring(i, chunkSize));
}
Here's an extension method that should do the trick (sans LINQ just to keep things clear):
public static string[] SplitLength(this string val, int length)
{
var parts = new List<string>();
for(int i = 0; i < val.Length; i += length)
{
parts.Add(val.Substring(i * length, length));
}
return parts.ToArray();
}