Results 1 to 3 of 3

Thread: [RESOLVED] Putting random text/numbers/symbols between text?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2009
    Posts
    193

    Resolved [RESOLVED] Putting random text/numbers/symbols between text?

    is their a way to do this to text? EX : 1p2a;s\s4w/o4r=dg

    It spells out password

  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: Putting random text/numbers/symbols between text?

    Sure, just define a list of characters that you want to be able to follow the character from your main string and insert a random one:

    Code:
            Dim s As String = "password"
            Dim sb As New StringBuilder
            Dim r As New Random
            ' list of valid characters to use after each character
            Dim alphabet As String = "1234567890/;'[]\-+|"":?ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!@#$%^&*()"
            For Each c As Char In s
                sb.Append(c)
                sb.Append(alphabet.Substring(r.Next(0, alphabet.Length), 1))
            Next
    
            MessageBox.Show(sb.ToString())

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Putting random text/numbers/symbols between text?

    When you're talking about anything random your pretty much talking about using a Random object to generate a random number and then using that number appropriately for the app, e.g. to convert to a Char.

    In your case you can loop through the characters in a String and alternately add a random Char to a StringBuilder and then a Char from the String. At the end you'll have a string like you want.

    Note that you can loop through the characters in a String using a For or For Each loop as though it was an array.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width