c# - generating string from exited characters -


i have character array shown below :

char[] pwdchararray = "abcdefghijklmnopqrstuvwxyzabcdefg" +             "hijklmnopqrstuvwxyz0123456789`~!@#$%^&*()-_=+[]{}\\|;:'\",<" +              ".>/?".tochararray(); 

and char array, want generate string of minimum length 7 , characters in string should above char array. how operation?

generate 7 random numbers between 0 , yourarray.length -1. pick corresponding char in array , put in final string.

here code stringbuilder:

stringbuilder sb = new stringbuilder(); random random = new randdom(); for(int i=0; i<7; i++) {     sb.append(pwdchararray[random.nextint(0, pwdchararray.length -1)]); } return sb.tostring(); 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -