Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Closed Thread
Old 07-30-2009, 06:13 AM   #1 (permalink)
 
Newb Techie

Join Date: Nov 2008

Posts: 3

uplink600 is on a distinguished road

Default Javascript Code Required

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 an array wordArray[0] = 'hello world'

....then I need to create a new string consisting of 11 underscore characters (one for each character) 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
uplink600 is offline  
Old 07-30-2009, 08:50 AM   #2 (permalink)
 

Join Date: Jul 2005

Location: England

Posts: 2,159

kmote has a spectacular aura aboutkmote has a spectacular aura about

Default Re: Javascript Code Required

Code:
var s = "Hello world";
var s2 = "";

document.write(s + "(");
document.write(s.length + ")" + "<br/>");

for(var i = 0; i < s.length; i++)
{
	s2 += "_";
}
document.write(s2 + "(");
document.write(s2.length + ")" + "<br/>");
bleh
__________________
MSI P43 Neo|Enermax Pro82+ 425W|E5200|silent 8500GT|250GB Samsung spinpoint F1|Samsung SATA DVD RW|4GB Corsair|Antec SOLO|openSUSE11


There are in order of increasing severity: lies, darn lies, statistics, and computer benchmarks. - diskinfo man page
kmote is online now  
Old 07-30-2009, 11:02 AM   #3 (permalink)
 
Newb Techie

Join Date: Nov 2008

Posts: 3

uplink600 is on a distinguished road

Default Re: Javascript Code Required

Thank you. I'll give that a try, your help is appreciated.
uplink600 is offline  
Old 08-08-2009, 12:19 PM   #4 (permalink)
CrazeD's Avatar
 
Wizard Techie

Join Date: Feb 2006

Location: Maine

Posts: 3,683

CrazeD will become famous soon enough

Send a message via AIM to CrazeD Send a message via MSN to CrazeD
Default Re: Javascript Code Required

Code:
var str = 'Hello World!';
var str2 = '';

while (str2.length != str.length)
{
	str2 += '_';
}

document.write(str2);
Mine's shorter!


__________________

Need website help? PM me!
CrazeD is offline  
Old 08-08-2009, 01:56 PM   #5 (permalink)
 

Join Date: Jul 2005

Location: England

Posts: 2,159

kmote has a spectacular aura aboutkmote has a spectacular aura about

Default Re: Javascript Code Required

Hahah you for the win!
__________________
MSI P43 Neo|Enermax Pro82+ 425W|E5200|silent 8500GT|250GB Samsung spinpoint F1|Samsung SATA DVD RW|4GB Corsair|Antec SOLO|openSUSE11


There are in order of increasing severity: lies, darn lies, statistics, and computer benchmarks. - diskinfo man page
kmote is online now  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
wincodecpro infestation clcrutch Virus - Spyware Protection / Detection 16 05-18-2009 07:09 PM
Javascript code & tutorials oldskool Programming Discussions 4 02-01-2009 05:20 PM
Hijack log bdruff HijackThis Logs (finished) 22 01-07-2009 11:33 PM
PHP: How to modify a downloaded JavaScript code and partly change the code within it? LincolnX Programming Discussions 4 01-25-2008 04:25 PM
JavaScript Botnet Code Leaked To Internet Osiris Virus - Spyware Protection / Detection 0 04-02-2007 09:05 PM