<html>
<body>
<textarea id="txt" rows="10" cols="40"></textarea>
<script type="text/javascript">
String.prototype.TrimLeft = function (chars) {
//debugger;
var re = chars ? new RegExp("^[" + chars + "]+/", "g")
: new RegExp(/^\s+/);
return this.replace(re, "");
}
String.prototype.TrimRight = function (chars) {
var re = chars ? new RegExp("[" + chars + "]+$/", "g")
: new RegExp(/\s+$/);
return this.replace(re, "");
}
String.prototype.Trim = function (chars) {
return this.TrimLeft(chars).TrimRight(chars);
}
var d = " ,asda,asdasd,asdasdads,asdasd, ";
var ta = document.getElementById("txt");
var sonuc = d.Trim().Trim(',');
ta.value = sonuc;
</script>
</body>
</html>
Denemesi:
http://jsfiddle.net/jsfiddleCem/hWPSB/
Güzel RegExp örnekleri:
http://gabrieljones.com/working-with-regular-expressions-in-javascript/
Hiç yorum yok:
Yorum Gönder