Autor Zpráva
E5150
Profil
Zdravim,
potrebuji v JavaScriptu odstranit vsechny mezery z retezce (pr.: var string="11 2 22 3";).

Zkousel jsem string.replace(/s+/,''); - toto funguje jen pro prvni vyskyt mezer a dokaze nahradit jen znakem, a ne "prazdnem" ('')...

Nevite nekdo jak na to? Diky moc....
_LZ
Profil

var str = '11 2 22 3';
var reg = /s/g; // slash - backslash - s - slash - g

alert(str.replace(reg,''));
Joker
Profil
_LZ
Jednoduše řečeno, je potřeba za regulární výraz přidat modifikátor "g" pro nahrazení všech výskytů.
peta
Profil
http://www.volny.cz/peter.mlich/www.htm#mssub19
** www.visibone.com reg v JS
E5150
Profil
var str = '11 2 22 3';
var reg = /s/g; // slash - backslash - s - slash - g

alert(str.replace(reg,''));


Hoj ... moc to teda nefunguje ... vlastne vubec :) Zkousel jsi to?
E5150
Profil
Uz sem nasel chybu,
spravne: var reg = /s/g;

Diky za pomoc ;o)
E5150
Profil
Ono se tady nezobrazuje lomitko ... takze tim je vse jasne ... diky
Joker
Profil
E5150
No proto tam asi _LZ napsal i ten komentář: // slash - backslash - s - slash - g
E5150
Profil
JJ...uz je vse jasne :)
Toto téma je uzamčeno. Odpověď nelze zaslat.

0