I think something similar to the following will provide what you are looking for.
byte[] data = System.Text.Encoding.UTF8.GetBytes(theString).Take(2048).ToArray();
or
byte[] source = System.Text.Encoding.UTF8.GetBytes(theString); byte[] destination = new byte[2048]; Buffer.BlockCopy(source, 0, destination, 0, 2048);
Edit: added example comment ..
This will provide you with List<byte[]> 2KB pieces, it is worth noting that this is not written for efficiency, but rather as an example, although it will perform a task that is not configured for high performance.
string theString = new string('*', 1022574); byte[] allData = System.Text.Encoding.UTF8.GetBytes(theString); int numberOfChunks = (int)Math.Ceiling((double)(allData.Length) / 2048); List<byte[]> chunks = new List<byte[]>(numberOfChunks); for (int i = 0; i < numberOfChunks; i++) { chunks.Add(allData.Skip(i * 2048).Take(2048).ToArray()); }
source share