Introduction:
Description:
In previous articles I explained jQuery Remove first/last character from string, jQuery Drag and Drop Example and many articles relating to JQuery. Now I will explain how to remove or delete white spaces from string using JQuery in asp.net.
In previous articles I explained jQuery Remove first/last character from string, jQuery Drag and Drop Example and many articles relating to JQuery. Now I will explain how to remove or delete white spaces from string using JQuery in asp.net.
To
remove or delete white spaces from string we can use default jQuery
function trim() but it will remove only starting and ending spaces but spaces within string will be same
because of that we need to use regular expression to remove white spaces from
string for that we need to write codesnippet like as shown below
Remove all the white spaces from string
<script type="text/javascript">
$(document).ready(function()
{
var str = ' Welcome To
Aspdotnet - Suresh '
var newstr = str.replace(/\s/g,'')
// Remove white spaces from string
alert(newstr);
})
</script>
|
If
you want check this code in sample check below code
Example:
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1"
runat="server">
<title>jQuery Remove White spaces from string in asp.net</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">
<div>
String : <b>' Welcome To Aspdotnet -
Suresh '</b>
<input type="button" id="btnRemove" value="Remove White Spaces From String" /><br /><br />
</div>
<script type="text/javascript">
$(document).ready(function()
{
$('#btnRemove').click(function() {
var str = ' Welcome To
Aspdotnet - Suresh '
var newstr = str.replace(/\s/g, '')
// Remove white spaces from string
alert(newstr);
});
});
</script>
</form>
</body>
</html>
|
Live
Demo
To check Live demo
click on below button
|
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
0 comments :
Note: Only a member of this blog may post a comment.