Thursday 29 December 2016

how to find vowels in a string in javascript

how to find vowels in a string in javascript

Introduction:

Here I will explain how to find vowels in a string in  javascript. In javascript such a not inbuilt function to get how to find vowels in a string in javascript so I have create this small function to how to find vowels in a string in javascript . It is easiest way to  how to find vowels in a string in javascript.

In previous post I explained System.Array' does not contain a definition for 'Count' how to access session in class c# how to create chat application in asp.net using c# sql query to get daily count and many article about Asp.net javascript and C#

Search:

how to find vowels in a string in javascript


Javascript function:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function VowelsData() {
    var Data = document.getElementById('txtData').value;
    if (Data == "")
    {
        alert('Enter value to check find vowels in a string');
        return;
    }
    var Count = 0;
    var Vowels = "";
    for (var Counter = 0; Counter < Data.length; Counter++) {
        if (Data.charAt(Counter).match(/[a-zA-Z]/) != null) {
            if (Data.charAt(Counter).match(/[aeiouAEIOU]/)) {
                Vowels = Vowels + Data.charAt(Counter);
                Count++;
            }
        }
    }
    if (Vowels == "")
    {
        Vowels = "Oops No Vowels";
    }
    document.getElementById('lblVowels').innerHTML = Vowels;
    document.getElementById('lblVowelsCount').innerHTML = Count;
}



Complete Example for how to find vowels in a string in javascript:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<html>
<head>
    <title>how to find vowels in a string in javascript</title>
    <script>
function VowelsData() {
    var Data = document.getElementById('txtData').value;
    if (Data == "")
    {
        alert('Enter value to check find vowels in a string');
        return;
    }
    var Count = 0;
    var Vowels = "";
    for (var Counter = 0; Counter < Data.length; Counter++) {
        if (Data.charAt(Counter).match(/[a-zA-Z]/) != null) {
            if (Data.charAt(Counter).match(/[aeiouAEIOU]/)) {
                Vowels = Vowels + Data.charAt(Counter);
                Count++;
            }
        }
    }
    if (Vowels == "")
    {
        Vowels = "Oops No Vowels";
    }
    document.getElementById('lblVowels').innerHTML = Vowels;
    document.getElementById('lblVowelsCount').innerHTML = Count;
}
    </script>
</head>
<body>
    <h1>how to find vowels in a string in javascript</h1>
    <div style="padding: 50px">
<table border="0" cellpadding="3" cellspacing="3">
<tr>
    <td>Enter Input :
    </td>
    <td>
        <input type='text'  id='txtData' >
    </td>
</tr>
    <tr>
    <td colspan="2">
        <input type='button' value='Find Vowels' onclick="VowelsData();">
    </td>
</tr>
<tr>
    <td>Total Vowels Count :
    </td>
    <td>
        <label id="lblVowelsCount"></label>
    </td>
</tr>
<tr>
    <td>Total Vowels :
    </td>
    <td>
            <label id="lblVowels"></label>
    </td>
</tr>
</table>
    </div>
</body>
</html>

You might also like

1. file type validation in jquery
2. file size validation in jquery
3. calling web service without adding web reference
4. How to bind CheckBoxList from database
5. How to bind DropdownList from database

/>

get month number from month name using javascript

get month number from month name using javascript

Introduction:

Here I will explain how to get month number from month name using javascript. In javascript such a not inbuilt function to get month number from month name so I have create this smaal function to get month number from month name using javascript. It is easiest way to convert month name to month number in javascript.

In previous post I explained System.Array' does not contain a definition for 'Count' how to access session in class c# how to create chat application in asp.net using c# sql query to get daily count and many article about Asp.net javascript and C#

Search:

how to get month number from month name using Javascript
get month number from month name


Eample:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>get month number from month name using javascript</title>
    <script>
        function getMonthFromName(MonthName) {
            var Month = 1;
            switch (MonthName) {
                case "January":
                    Month = 1;
                    break;
                case "February":
                    Month = 2;
                    break;
                case "March":
                    Month = 3;
                    break;
                case "April":
                    Month = 4;
                    break;
                case "May":
                    Month = 5;
                    break;
                case "June":
                    Month = 6;
                    break;
                case "July":
                    Month = 7;
                    break;
                case "August":
                    Month = 8;
                    break;
                case "September":
                    Month = 9;
                    break;
                case "October":
                    Month = 10;
                    break;
                case "November":
                    Month = 11;
                    break;
                case "December":
                    Month = 12;
                    break;
            }
            return Month;
        }
        function getMonthNumber() {
            var MonthNo = getMonthFromName(document.getElementById('txtMonthName').value);
            document.getElementById('lblMonthNumber').innerHTML = MonthNo.toString();
        }

    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <h1>get month number from month name using javascript</h1>
            <input type="text" id="txtMonthName" />
            <input type="button" value="Get Month Number" onclick="getMonthNumber();" />
            <br />
            Month Number is:
            <label ID="lblMonthNumber"></label>
        </div>
    </form>
</body>
</html>

You might also like

1. file type validation in jquery
2. file size validation in jquery
3. calling web service without adding web reference
4. How to bind CheckBoxList from database
5. How to bind DropdownList from database

Wednesday 16 November 2016

remaining characters counter javascript


remaining characters counter javascript

Introduction:

Here I will explain remaining characters counter javascript or count number of characters in textbox javascript. Some times show the character counter to remaining for textbox or textarea at client side. For this we need to use onkeyup event of textbox or textarea.

In previous post I explained System.Array' does not contain a definition for 'Count' how to access session in class c# how to create chat application in asp.net using c# sql query to get daily count and many article about Asp.net javascript and C#

javascript character count textarea
count number of characters in textbox javascript
textbox character counter jquery
textarea character count jquery
javascript character countdown
validate number of characters in textbox javascript
jquery character countdown
textbox character counter in asp.net c#

Eample:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
<html>
 <head>
    <title>remaining characters counter javascript</title>
    <script type="text/javascript">
  function Counter() {
  var i = document.getElementById("txtMessage").value.length;
  document.getElementById("lblCounter").innerHTML = 10 - i;
    }
     </script>
    </head>
<body>
 <h1> Show Number of Characters Remaining in Textbox or Textarea  </h1>
 example of remaining characters counter javascript
 <br><br>
 Enter Name(max length:10): <input id='txtMessage' type='text' MaxLength="10" onkeyup="Counter()" />
 <lable id='lblCounter'> 10</label>
 <br><br>
</body>
<html>

You might also like

1. file type validation in jquery
2. file size validation in jquery
3. calling web service without adding web reference
4. How to bind CheckBoxList from database
5. How to bind DropdownList from database

Tuesday 15 November 2016

System.Array' does not contain a definition for 'Count' and no extension method 'Count' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?

System.Array' does not contain a definition for 'Count' and no extension method 'Count' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?

This error we got many times at runt time.
We need to add namespace for this


Soulution

using System.Linq;


This error may be like these:
System.Array does not contain a definition for 'Count'
system.array does not contain a definition for skip
'system.array' does not contain a definition for 'add'
c# system array does not contain a definition for where
'system.array' does not contain a definition for 'split'
system array does not contain a definition for length
'system.array' does not contain a definition for 'contains'
string does not contain a definition for length

how to access session in class c#

how to access session in class c#
Here I will explain how to access session in class c#, we already use session in any code behind like page code. But some time required to access session value in class file or set session value in class file then we need to use like following syntax.

Example


string Value =Convert.ToString(HttpContext.Current.Session["Id"]);

this code working fine in any code behind file like default.aspx.cs



Convert.ToString(Session["Id"])


How to access session variables from any class in ASP.NET C#
the name session does not exist in the current context
how to access session in class c#

Saturday 28 May 2016

how to create chat application in asp.net using c#


how to create chat application in asp.net using c#

Introduction:

Here I will explain how to create chat application in asp.net using c# or how to create chat application using WebSocket. If you want to create simple chat application in asp.net using c# then do following step and you can chat using your chat application.

we can create chat application using Jquery Ajax method, SignalR and WebSocket .

So, Now I explaining how to create chat application in asp.net using c# with WebSocket.

Description: 

In previously post I explained to  
Three tier architecture in asp.net
Remove .aspx from url in asp.net
Temp table in sql
Change the column name or datatype or size in sql server
Stored procedure with paging sql server
Calling web service without adding web reference 



how to create chat application in asp.net using c#
How to create chat application in asp.net using websocket
chat application in asp.net using c#
how to create chat application in asp.net using c# like facebook
simple chat application in asp.net using c#
chat application in asp.net using c# source code
asp net chat application source code
asp.net chat application with database
chat application in asp.net using c# code project
web based chat application in asp net c#



WebSocket:


WebSocket is a protocol providing full-duplex communication channels over a single TCP connection.
It is two-ways connections
It working only in HTML 5 
It's for real time data app like chat, stock market app and online game



WebSocket - server side:

Asp.net 4.5 and above framework
IIS 8 and above IIS on server


STEP : how to create chat application in asp.net using c#



Now follow this Step by step to create chat application in asp.net using WebSocket

Create new project or website
Add WebSockets.dll in project
Add Class file(MicrosoftwebSockets2.cs) in App_Code file
Add Handler(WebSocketServer2.ashx) file in your project
Add HTML file (index.html)

Now your project solution explorer like below


Once you add all above files in your project or website then paste below code in your asp.net project.

Open your App_Code/MicrosoftwebSockets2.cs class file and paste following code



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using Microsoft.Web.WebSockets;
public class MicrosoftwebSockets2 : WebSocketHandler
{
        private static WebSocketCollection clients = new WebSocketCollection();
        private string name;

        public MicrosoftwebSockets2()
        {
//cn = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
        }
        public override void OnOpen()
        {
            name = this.WebSocketContext.QueryString["name"];
            clients.Add(this);
            clients.Broadcast(name + " has connected.   Total online user:"+clients.Count());
        }
        public override void OnMessage(string message)
        {
            clients.Broadcast(string.Format("{0} : {1} ", name, message));
        }
        public override void OnClose()
        {
            clients.Remove(this);
            clients.Broadcast(string.Format("{0} has gone away ", name));
        }
    
      
}

Open your WebSocketServer2.ashx Handler file from root and paste following code

<%@ WebHandler Language="C#" Class="WebSocketServer2" %>
using System;
using System.Web;

using Microsoft.Web.WebSockets;
using System.Web.WebSockets;
using System.Net.WebSockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;


public class WebSocketServer2 : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        if (context.IsWebSocketRequest)
        {
            context.AcceptWebSocketRequest(new MicrosoftwebSockets2());
        }
    }
    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}



Open your index.html file from root and paste following code




<html xmlns="http://www.w3.org/1999/xhtml">
<head>

    <title>How to create chat application in asp.net using WebSocket</title>

    <script src="jquery-1.9.1.js" type="text/javascript"></script>

    <script type="text/javascript">

        $(document).ready(function () {

            $('#txtMessage').keypress(function (e) {
                if (e.which == 13) {
                    ws.send($('#txtMessage').val());
                    $('#txtMessage').val('');
                    $('#txtMessage').focus();
                    return false;
                }
            });

            var name = prompt('what is your name?:');

            //Add your website or project URL here
            var url = 'ws://localhost:8945/WebSocketServer2.ashx?name=' + name;

            ws = new WebSocket(url);
            ws.onopen = function () {
                $('#messages').prepend('Connected <br/>');
                $('#cmdSend').click(function () {
                    ws.send($('#txtMessage').val());
                    $('#txtMessage').val('');
                    $('#txtMessage').focus();
                });
            };

            ws.onmessage = function (e) {
                if (e.data.search(name) == -1) {
                    $('#chatMessages').css("color", "green");
                }
                else {
                    $('#chatMessages').css("color", "blue");
                }
                $('#chatMessages').prepend(e.data + '<br/>');
                $('#txtMessage').focus();
            };

            $('#cmdLeave').click(function () {
                ws.close();
            });

            ws.onclose = function () {
                //$('#chatMessages').prepend('Closed <br/>');
                $('#chatMessages').prepend(name+ ' - You are Log out.<br/>');
            };

            ws.onerror = function (e) {
                $('#chatMessages').prepend('ERROR - Oops something went wront <br/>');
            };

        });

    </script>
</head>
<body>
    <br />
    <br />
    <h1> Chat example in asp.net using webSocket</h1>
    <input id="txtMessage" style="width:40%" />

    <input id="cmdSend" type="button" value="Send" />

    <input id="cmdLeave" type="button" value="Log out" />

    <br />

    <div id="chatMessages" />
   
</body>
</html>


Now your chat application is ready to use. Just run your project or website in two different browser and you can chat with your chat application.
If you want to save user chat history that time you can use insert data code in class file and save it.

You can ask question about it you can ask here. !





Asp.net tutorials