Here I will explain how to trim or remove first/last characters from string using JQuery in asp.net.
In previous posts I explained jQuery Add/Remove CSS Class, jQuery slideUp, slideDown and slideToggle Example, Draggable and Resizable example, add fade in effect to page, Password strength jquery plugin examples and many articles relating to JQuery. Now I will explain how to trim or remove first or last characters from string using JQuery in asp.net.
<script type="text/javascript">
$(document).ready(function()
{
var str = '$$$Welcome To
Aspdotnet-Suresh'
var newstr = str.substr(3) // This
will Remove first 3 characters from string
alert(newstr);
})
</script>
|
<script type="text/javascript">
$(document).ready(function()
{
var str = 'Welcome To
Aspdotnet-Suresh$$'
var newstr = str.substr(0,str.length-2) // This will Remove Last 2 characters from string
alert(newstr);
})
</script>
|
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>jQuery Trim/Remove first/last characters 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>
<script type="text/javascript">
$(document).ready(function()
{
$('#btnFirst').click(function() {
var str = '$$$Welcome To
Aspdotnet-Suresh'
var newstr = str.substr(3) // Remove
First 3 characters from string
alert(newstr);
})
$('#btnLast').click(function() {
var str = 'Welcome To
Aspdotnet-Suresh$$'
var newstr = str.substr(0, str.length - 2) // Remove Last 2 characters from string
alert(newstr);
})
})
</script>
</head>
<body>
<form id="form1"
runat="server">
<div>
String1 : <b>$$$Welcome
To Aspdotnet-Suresh</b>
<input type="button" id="btnFirst" value="Remove First 3 Characters" /><br /><br />
String2 : <b>Welcome To
Aspdotnet-Suresh$$</b>
<input type="button" id="btnLast" value="Remove Last 2 Characters" />
</div>
</form>
</body>
</html>
|
|
|
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. |
|||
Subscribe by RSS
Subscribe by Email
|
|||
|
|
|
Subscribe by RSS
Subscribe by Email
0 comments :