"Emil" <hif@zniffer.dk> skrev i en meddelelse
news:b7h5u6$l4s$1@sunsite.dk...
> jeg skal bruge et javascript funktion med ét input-parameter, som
> finder længden af længste ord i input-strengen ...
>
>
>
>
> Helts inden imorgen.. :/ plz help.. :(
>
> --
> Vil du lære at kode HTML, XHTML, CSS, SSI eller ASP?
> - Pædagogiske tutorials på dansk
> - Kom godt i gang med koderne
> KLIK HER! =>
http://www.html.dk/tutorials
Hej Emil.
Her en lille hurtigt lavet funktion, har ikke gennemtestet den.
<script language="javascript1.2">
/*
Finds the length of the longest word in a string.
Assumes that words in string are only separated by spaces.
Dont think it will work with strings consisting of
multiple lines!
*/
function getLongestWord( inputString ) {
var longestVal = 0;
var tmpArray = inputString.split( " " ); // Splits the string on spaces
for ( i = 0; i < tmpArray.length; i++ ) { // Iterate array and find
longest word
if ( tmpArray[i].length > longestVal ) {
longestVal = tmpArray[i].length // Longer word found, update variables
}
}
return longestVal;
}
</script>
Venlig Hilsen
Jacob Winther
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (
http://www.grisoft.com).
Version: 6.0.471 / Virus Database: 269 - Release Date: 11-04-2003