The RandomCustomStrings class in the Promezio.RandomCustomStrings namespace provides a simple yet flexible way to generate random strings in C#. This can be highly useful in scenarios like generating random IDs, passwords, test data, and more. The class allows for extensive customization through the StringConfig class, enabling users to specify the length and character types of the generated strings.
- Customizable String Length: Define the length of the generated string.
- Character Type Inclusion: Opt to include uppercase, lowercase, numbers, special characters, and/or custom characters in the string.
- Custom Character Support: Add any set of custom characters to the string generation pool.
-
Add Namespace: Include the namespace in your code.
using Promezio.RandomCustomStrings;
-
Create Configuration: Instantiate a
StringConfigobject with your desired settings.StringConfig config = new StringConfig( lenght: 10, containUppercase: true, containLowercase: true, containNumbers: true, containSpecialChars: true );
-
Generate String: Use the
Generatemethod to create a random string.string randomString = RandomCustomStrings.Generate(config);
StringConfig config = new StringConfig(15, containUppercase: true, containNumbers: true);
string myRandomString = RandomCustomStrings.Generate(config);
Console.WriteLine(myRandomString);uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
lowercase = "abcdefghijklmnopqrstuvwxyz";
numbers = "0123456789";
specialChars = ",.;:-_*()%$&?!=/"; StringConfig config = new StringConfig(10,
customChars: "@£\|",
containCustomChars: true);
string randomString = RandomCustomStrings.Generate(config);Feel free to fork this project, submit pull requests, or report bugs and feature requests on the issue tracker.
This project is licensed under the MIT License - see the LICENSE file for details.
Coded by Gioele Stefano Luca Fierro
Sponsored by Promezio