String Function Using Javascript and C#
String Function uppercase,index,substring Using Javascript and C# in Asp.Net.
DEMO
C# Coding
String Function uppercase,index,substring Using Javascript and C# in Asp.Net.
DEMO
Html Coding
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
//String Concatination
function concat()
{
var Str1 = "Dot";
var Str2 = "Net";
var c = Str1.concat(Str2.toString());
alert(c.toString());
}
//String IndexOf
function indexof()
{
var str1 = "Welcome to Dotnet Drizzles";
alert(str1.indexOf("Dotnet").toString());
}
//String UpperCase
function Ucase()
{
var Str1 = "Dotnet Drizzzles";
alert(Str1.toUpperCase());
}
// String Last indexof
function LastIndexof()
{
var str1 = "Welcome To Dotnet Drizzles and Asp Dotnet";
alert(str1.lastIndexOf("Dotnet"));
}
// String Substrings
function Substring()
{
var str1 = "DRIZZLES";
alert("Substr="+str1.substr(2,3)+","+"Substring="+str1.substring(2,3));
}
// String Replace
function replac()
{
var str1 = "Dotnet";
alert(str1.replace("Dotnet", "DotnetDrizzles"));
}
</script>
</head>
<body>
<form runat="server">
<div align="center">
<table>
<tr><td>Javascript</td><td>C#</td></tr>
<tr><td><input type="button" value="Concat" onclick="concat();" /></td><td><asp:Button ID="Button1" runat="server" Text="Concat" OnClick="Button1_Click1" /></td></tr>
<tr><td> <input type="button" value="IndexOf" onclick="indexof();" />
</td><td> <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="IndexOf" />
</td></tr>
<tr><td> <input type="button" value="LastIndexOf" onclick="LastIndexof();" />
</td><td> <asp:Button ID="Button4" runat="server" OnClick="Button4_Click" Text="LastIndexOf" />
</td></tr>
<tr><td> <input type="button" value="Uppercase" onclick=" Ucase();" />
</td><td> <asp:Button ID="Button3" runat="server" OnClick="Button3_Click" Text="Uppercase" />
</td></tr>
<tr><td> <input type="button" value="Substring" onclick="Substring();" />
</td><td> <asp:Button ID="Button5" runat="server" OnClick="Button5_Click" Text="Substring" />
</td></tr>
<tr><td> <input type="button" value="Replace" onclick="replac();" />
</td><td><asp:Button ID="Button6" runat="server" OnClick="Button6_Click" Text="Replace" /></td></tr>
<tr><td colspan="2"><asp:Label ID="Label1" ForeColor="Red" runat="server" Text="Label"></asp:Label></td></tr>
</table>
</div>
</form>
</body>
</html>
C# Coding
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
public partial class StringFunctions : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click1(object sender, EventArgs e)
{
//Concat
string Str1 = "DotNet ";
string Str2 = "Drizzles";
Label1.Text = Str1 + Str2;
}
protected void Button2_Click(object sender, EventArgs e)
{
//IndexOf
string Str1 = "Welcome to Dotnet Drizzles";
Label1.Text = Str1.IndexOf("Dotnet").ToString();
}
protected void Button3_Click(object sender, EventArgs e)
{
//UpperCase
string Str1 = "Dotnet Drizzzles";
Label1.Text = Str1.ToUpper();
}
protected void Button4_Click(object sender, EventArgs e)
{
//LastIndexOf Dotnet in str1
string str1 = "Welcome To Dotnet Drizzles and Asp Dotnet";
Label1.Text = str1.LastIndexOf("Dotnet").ToString();
}
protected void Button5_Click(object sender, EventArgs e)
{
//Substring
string str1 = "DRIZZLES";
Label1.Text = str1.Substring(2,3).ToString();
}
protected void Button6_Click(object sender, EventArgs e)
{
//Replace
string str1 = "Dotnet";
Label1.Text = str1.Replace("Dotnet", "DotnetDrizzles");
}
}
0 comments:
Post a Comment