|
|
#1 |
|
Beta Member
Join Date: Jul 2009
Posts: 2
|
Good Afternoon.
I need help with some code please. I need to create a string of underscore characters and the string has to be the same length as another existing string or an element in an array. So for example if I have the following...... A string 'hello world' or wordArray[0] = 'hello world' ....then I need to create a new string consisting of 11 underscore characters or however many characters are in the initial string or array element. Hope you can help as I can't find any easy way to do this. Thanks BG |
|
|
|
|
|
#2 |
|
In Runtime
|
you are going to need it to print an underscore for each character in the word array.
and welcome to CF
__________________
-Zack |
|
|
|
|
|
#3 |
|
Beta Member
Join Date: Jul 2009
Posts: 2
|
Sorry but I don't understand your reply. Thank you for your welcome.
BG |
|
|
|
|
|
#4 |
|
In Runtime
|
In the new string, you are going to have to add an underscore for each character in the string value
__________________
-Zack |
|
|
|
|
|
#5 | |
|
Fully Optimized
Join Date: Oct 2008
Posts: 2,345
|
Quote:
Here you go dude; Code:
<script type="text/javascript">
function replace() {
var string = document.getElementById('string').value;
var len = string.length;
var underscores = new Array();
for (var i = 0; i < len; i++) {
underscores[i]="_";
}
document.getElementById('spacers').innerHTML=underscores.join("");
}
</script>
<button onclick="replace()">Replace</button>
<input type="text" id="string" value="one">
<span id="spacers"></span>
__________________
Everyone's Favorite Turd xD ET: "Phone home!" Geek: "ping 127.0.0.1" "If that guy knew half the $h*t that I know, his fuzzy little head would explode. " - Matthew Farrell |
|
|
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|