...

View Full Version : adding randomal "0" to string



sasha85
10-09-2007, 05:53 PM
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?:rolleyes:

Daemonspyre
10-09-2007, 06:16 PM
Hey Sasha --

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

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


<% 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.

miranda
10-09-2007, 07:55 PM
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

sasha85
10-10-2007, 11:23 AM
solved

thank u !



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum