Hi Friends,in this article i will explain about How do I extract a string of text that lies between two (parenthesis) in ASP.NET using C#.NET/VB.NET.
I already explained in the previous articles about Sorting GridView By Columns Header In Asp.Net Ascending and Descending in ASP.NET using C#/VB.NET , Ajax ModalPopUpExtender Example to edit the GridView row values in ASP.NET and ASP.NET: Move Items from One ListBox to Another ListBox using C#/VB.NET
In ASP.NET:
I already explained in the previous articles about Sorting GridView By Columns Header In Asp.Net Ascending and Descending in ASP.NET using C#/VB.NET , Ajax ModalPopUpExtender Example to edit the GridView row values in ASP.NET and ASP.NET: Move Items from One ListBox to Another ListBox using C#/VB.NET
In ASP.NET:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>How do I
extract a string of text that lies between two (parenthesis) using .NET?</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DdlExtract"
runat="server">
<asp:ListItem Value="0">--Select--</asp:ListItem>
<asp:ListItem Value="1">A(Kishore)</asp:ListItem>
<asp:ListItem Value="2">B(SaiR)</asp:ListItem>
<asp:ListItem Value="3">C(Anil)</asp:ListItem>
<asp:ListItem Value="4">D(Krish)</asp:ListItem>
</asp:DropDownList>
<asp:Button runat="server"
ID="btnSubmit"
Text="Submit"
onclick="btnSubmit_Click"
/>
<asp:Label ID="lblSelect"
runat="server"></asp:Label>
</div>
</form>
</body>
</html>
|
In C#:
using System;
using
System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using
System.Web.UI.WebControls;
public partial class Ddl : System.Web.UI.Page
{
protected
void Page_Load(object
sender, EventArgs e)
{
}
protected
void btnSubmit_Click(object
sender, EventArgs e)
{
string ddlapp = DdlExtract.SelectedItem.ToString();
int start = ddlapp.IndexOf("(");
int end = ddlapp.IndexOf(")");
string result = ddlapp.Substring(start + 1, end -
start - 1);
lblSelect.Text =
result;
lblSelect.ForeColor =
System.Drawing.Color.Red;
}
}
|
In VB.NET:
Imports System.Web
Imports System.Web.UI
Imports
System.Web.UI.WebControls
Partial Class DdlTest
Inherits
System.Web.UI.Page
Protected
Sub Page_Load(ByVal
sender As Object,
ByVal e As
System.EventArgs) Handles
Me.Load
End
Sub
Protected
Sub btnSubmit_Click(ByVal
sender As Object,
ByVal e As
System.EventArgs) Handles
btnSubmit.Click
Dim
ddlapp As String
= DdlExtract.SelectedItem.ToString()
Dim start As Integer = ddlapp.IndexOf("(")
Dim [end] As Integer = ddlapp.IndexOf(")")
Dim result As String = ddlapp.Substring(start + 1, [end] - start
- 1)
lblSelect.Text =
result
lblSelect.ForeColor =
System.Drawing.Color.Red
End
Sub
End Class
|
When you select the value DropDownList and click on Submit button then it will show the value in the parenthesis value in the selectedItem in the DropDownList.
No comments:
Post a Comment