Related Posts Plugin for WordPress, Blogger...

About

Follow Us

Thursday 9 July 2015

Introduction:

In this article I will explain how to remove white spaces from the given string. This can be done by using code in code behind but it is time consuming. Javascript give us a easy way to remove white spaces from the string.

Following Javascript We use to remove white spaces from given string:

<script type="text/javascript">
    $(document).ready(function () {
        $('#btnFilter').click(function () {
            var str = ' Hello, World. This is Maziksolutions.'
            var newstr = str.replace(/\s/g, '') // Remove white spaces from string
            alert(newstr);
        });
    });
</script>

Source Code:
Full Source code of Sample Application:

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Remove White spaces from String Using Jquery</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
</script>
</head>
<body>
<form id="form1" runat="server"><center>
<div>
String : <b>'   Hello, World. This is Maziksolutions.  '</b><br />
<br /><input type="button" id="btnFilter" value="Remove White Spaces From String" /><br /><br />
</div></center>
<script type="text/javascript">
    $(document).ready(function () {
        $('#btnFilter').click(function () {
            var str = ' Hello, World. This is Maziksolutions.'
            var newstr = str.replace(/\s/g, '') // Remove white spaces from string
            alert(newstr);
        });
    });
</script>
</form>
</body>
</html>


Use this code and check result. We can use this code in our applications.
Categories: , ,

0 comments:

Post a Comment