I have a requirement to test some load issues with regards to file size. I have a windows application written in C# which will automatically generate the files. I know the size of each file, ex. 100KB, and how many files to generate. What I need help with is how to generate a string less than or equal to the required file size.
pseudo code:
long fileSizeInKB = (1024 * 100); //100KB int numberOfFiles = 5; for(var i = 0; i < numberOfFiles - 1; i++) { var dataSize = fileSizeInKB; var buffer = new byte[dataSize]; using (var fs = new FileStream(File, FileMode.Create, FileAccess.Write)) { } }
Insert method creates a new string by inserting a string into a specified position in another string. This method uses a zero-based index. The following example inserts a string into the fifth index position of MyString and creates a new string with this value. C# Copy. string sentence = "Once a time."; Console.
You can always use the a constructor for string which takes a char
and a number of times you want that character repeated:
string myString = new string('*', 5000);
This gives you a string of 5000 stars - tweak to your needs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With