Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

jQuery Remove First/Last Character From String in Asp.net

Oct 8, 2012
Introduction

Here I will explain how to trim or remove first/last characters from string using
JQuery in asp.net.

Description:
  
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.

To remove or trim first/last characters we need to write the codesnippet like as shown below

Remove first 3 characters from string


<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>
Remove Last 2 characters from string


<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>
If you want check this code in sample check below code

Example:


<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>

Live Demo

To check Live demo click on below buttons

String1 : $$$Welcome To Aspdotnet-Suresh

String2 : Welcome To Aspdotnet-Suresh$$

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 RSS subscribe by email Subscribe by Email

0 comments :

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.