Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Sep 2007
    Posts
    179
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Smile adding randomal "0" to string

    i got a string- for example the word "CodingForums"
    i want somehow to add randomal char- for example "0", 3 times
    the output can look like this-
    "0C0odi0ngForums" "Co0ding0Foru0ms" "Co0din0gFor0ums" "0CodingForums00"
    what is the best way to do this?
    By the time u recognize this moment, This moment will be gone.

  • #2
    Regular Coder
    Join Date
    Mar 2007
    Posts
    505
    Thanks
    1
    Thanked 19 Times in 19 Posts
    Hey Sasha --

    You can use RND, RANDOMIZE, LEFT, and MID to solve this problem.

    NOTE: Rnd (Random) is not always random...

    Code:
    <% strAddChar = "Coding Forums"
    strToAdd = "0"
    '
    for x=1 to 3   				'where 3 = the number of times you want to add a character
    	y = Int(Int(Rnd) - (len(strAddChar) + 1) * Rnd + len(strAddChar) + Rnd)
    	strAddChar = LEFT(strAddChar,y) & strToAdd & MID(strAddChar,y+1,len(strAddChar))
    	Randomize
    next
    '
    response.write strAddChar
    response.flush %>
    YOU MAY RECEIVE AN ERROR!!! That's because Random isn't always random.
    To say my fate is not tied to your fate is like saying, 'Your end of the boat is sinking.' -- Hugh Downs
    Please, if you found my post helpful, pay it forward. Go and help someone else today.

  • #3
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,072
    Thanks
    4
    Thanked 8 Times in 8 Posts
    To ensure that you get a random number you MUST use the Randomize statement before you use Rnd. Otherwise the numbers will display in the same sequence every time

  • #4
    Regular Coder
    Join Date
    Sep 2007
    Posts
    179
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Exclamation problem

    solved

    thank u !
    Last edited by sasha85; 10-10-2007 at 01:18 PM.
    By the time u recognize this moment, This moment will be gone.


  •  

    Posting Permissions

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