|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
// replace swedish chars with HTML ones. function sweToHTML (context) { var breaking=0; while (breaking < 1) { breaking++; if (context = context.replace("å","å")) { breaking=0; } if (context = context.replace("Å","Å")) { breaking=0; } if (context = context.replace("ä","ä")) { breaking=0; } if (context = context.replace("Ä","Ä")) { breaking=0; } if (context = context.replace("ö","ö")) { breaking=0; } if (context = context.replace("Ö","Ö")) { breaking=0; } } return (context); } [/code] { Note! context.replace("Ö","Ö")) means, replace swedish character with a HTML one } First, the "breaker" is set to zero outside the loop. And if var breaking is less than 1, do the loop. In the loop, if a string.replace() is made, then reset the var breaking again, so that the loop happens again. If no changes are made, then var breaking is incremented once and once again, to quit the loop. Either I get an infinite loop of one that doesn't do anything. Please help ------------------ ¬ peterbe.com ¬ [This message has been edited by peterbe (edited August 14, 2000).] |
|
#2
|
|||
|
|||
|
SOLVED IT!
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre> function sweToHTML (context,onoff) { swechars = new Array("å","Å","ä","Ä","ö","Ö"); HTMLchars = new Array("å","Å","ä","Ä","ö","Ö"); if (onoff < 0) { alert("nntreverse order or arraystnn"); } var limit=0; while (limit < 1) { limit=1; for (i=0; i<swechars.length; i++) { if (context.match(swechars[i])) { context = context.replace(swechars[i],HTMLchars[i]); limit=0; } } } return (context); } [/code] ------------------ ¬ peterbe.com ¬ |
![]() |
| Viewing: Dev Shed Forums > Web Design > HTML Programming > Why doesn't this while loop work? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|