How do I replace a string with an array inside a string?
Posted: Fri Jun 30, 2006 11:23 am
If the subject line confused you, here's what I want to do:
I've got a string such as the following:
"Hello, my name is #Chris/Frank/John#, what is your name?"
I want to take what is inside the number signs (Chris/Frank/John), put it into an array and then pick a random choice from the list. The final result would be one of the following, chosen randomly:
"Hello, my name is Chris, what is your name?"
"Hello, my name is Frank, what is your name?"
"Hello, my name is John, what is your name?"
I know how to pick a random indexs from an array, I just don't know how to pull an array out of a string. Is is possible to insert a function directly into a string such as:
"Hello, my name is chooseOption(array("Chris","Frank","John")), what is your name?"
Thanks for your help!
I've got a string such as the following:
"Hello, my name is #Chris/Frank/John#, what is your name?"
I want to take what is inside the number signs (Chris/Frank/John), put it into an array and then pick a random choice from the list. The final result would be one of the following, chosen randomly:
"Hello, my name is Chris, what is your name?"
"Hello, my name is Frank, what is your name?"
"Hello, my name is John, what is your name?"
I know how to pick a random indexs from an array, I just don't know how to pull an array out of a string. Is is possible to insert a function directly into a string such as:
"Hello, my name is chooseOption(array("Chris","Frank","John")), what is your name?"
Thanks for your help!