Powered by Blogger.

Saturday, October 28, 2017

How to get substring from string using jQuery in asp.net?



Here we will discuss how we can retrieve sub string from string using jQuery in asp.net. We will do this inside an asp.net.

Here we can extract a substring out of string using substring() JavaScript method. Here we will do on a button click.

substring() method will take the start position and number of characters. If the second parameter is not specified then it will return till end.

Also you can read:
- How to get current page URL using jQuery in asp.net?

- Cross-page posting in Asp.Net

- Bind dropdownlist from enum in Asp.Net

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#btnGetString").on("click", function () {
                var mainString = "This is our main string.";
                var subString = mainString.substring(5, 16);
                alert(subString);
            });
        });
    </script>
    <br />
    <div class="row">
        <div class="col-md-4">
            <input type="button" id="btnGetString" value="Get sub string" /><br />
        </div>

    </div>

Once you click on the button, you can see the result like below:



get substring from string using jQuery

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#btnGetString").on("click", function () {
                var mainString = "This is our main string.";
                var subString = mainString.substring(5);
                alert(subString);
            });
        });
    </script>
    <br />
    <div class="row">
        <div class="col-md-4">
            <input type="button" id="btnGetString" value="Get sub string" /><br />
        </div>

    </div>

Onc you click on the button, you can see the result like below:

asp.net get substring from string using jQuery

Hope this will be helpful.





0 comments

Post a Comment