iOS Question Creating Random String

Discussion in 'iOS Questions' started by tufanv, Jun 10, 2015.

  1. tufanv

    tufanv Expert Licensed User

    Hello,

    in b4a i am using string functions library to create random string with 3 chars like :
    txtcountry.Text = s.RndChrGen(3,1)

    we dont have the library in b4i. How can i do stg like this ?

    TY
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Which characters are allowed in this string? What is the second parameter?
     
  3. tufanv

    tufanv Expert Licensed User

    only a to z I want it to create for example : ple,fkq,xju etc.. random 3 charachters from a to z.
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Code:
    Sub GenerateRandomString(Length As Int) As String
       
    Dim sb As StringBuilder
       sb.Initialize
       
    For i = 1 To Length
         sb.Append(
    Chr(Rnd(Asc("a"), Asc("z") + 1)))
       
    Next
       
    Return sb.ToString
    End Sub
     
    valentino s and tufanv like this.
Loading...