How to Generate formatted Alpha Numeric strings in C# -
How to Generate formatted Alpha Numeric strings in C# -
i want generate random string 5 alpha numeric characters, should generate 2 characters , other should numeric like
rl589 for have done like
var chars = "abcdefghijklmnopqrstuvwxyz0123456789"; var stringchars = new char[5]; var random = new random(); (int = 0; < stringchars.length; i++) { stringchars[i] = chars[random.next(chars.length)]; } var finalstring = new string(stringchars); but confused how arrange first 2 letters characters , next other should numeric. please help me anyone.
use 2 loops, illustration this:
var chars = "abcdefghijklmnopqrstuvwxyz"; var numbers = "0123456789"; var stringchars = new char[5]; var random = new random(); (int = 0; < 2; i++) { stringchars[i] = chars[random.next(chars.length)]; } (int = 2; < stringchars.length; i++) { stringchars[i] = numbers[random.next(numbers.length)]; } var finalstring = new string(stringchars); c#
Comments
Post a Comment