ASP.NET - Exact match
Asked By goldy gupta
10-Feb-12 03:45 AM
Helo to all i have an web application in c#.. i have an array
like
string[] arr = { "One", "Two", "Three" };
var target = "On";
var rr = Array.FindAll(arr, s => s.Contains(target)).ToArray();
Whats this doing that it gives the result ONE as 'On' is not in an array..
I wants to search with an exact word i.e On
i am searching a particular string in a whole array
kalpana aparnathi replied to goldy gupta
hi,
Try below for your solution:
bool contains = Regex.IsMatch("your full string", @"\bhere your exact serchingword\b"); // yields true
goldy gupta replied to kalpana aparnathi
See search with a particular index in an array..
But i want to search in whole array item.. suppose i have an array like
string[] arr = {"Kshama","Kshms","Kshamta","<span>Gold</Sapn>","Goldy","Goldinjh" };
Now i am serrching Gold in a whole array.. The result should only be 1
Sandeep Mittal replied to goldy gupta
Use "Equals" instead of "contains"
string[] arr = { "One", "Two", "Three" };
var target = "One";
var rr = Array.FindAll(arr, s => s.Equals(target)).ToArray();
kalpana aparnathi replied to goldy gupta
hi,
use that expression with for loop match it with your string index array withing serching match string value so you could find your match with it.
Thanks,
goldy gupta replied to Sandeep Mittal
See Equals will compare the whole string..
I am searching for Gold and Gold is inside <span>Gold</span>
so Equals will not give the result which we are expecting...
Danasegarane Arunachalam replied to goldy gupta
Use the Where Clause of LINQ extensions
string[] arr = { "My", "Name", "Test" };
var target = "My";
var results = arr.Where(s => s==target).ToArray();
The example find the exact match of My in the array collection arr.
If found then it returns the matching values....
goldy gupta replied to Danasegarane Arunachalam
Plz try to understand..The thing which you told i Know
but see my array is like
string[] arr = {"Kshama","Kshms","Kshamta","<span>Gold</Sapn>","Goldy","Goldinjh" };
Now i am serrching Gold in a whole array.. The result should only be 1 .. But when i am searching its retrieving
Gold
Goldy
Goldinjh
and with your code its not matching because it will only serach the whole text not the containning
Sandeep Mittal replied to goldy gupta
string[] arr = { "Kshama", "Kshms", "Kshamta", "<span>Gold</Sapn>", "Goldy", "Goldinjh" };
var target = "Gold";
var rr = Array.FindAll(arr, s => Regex.Replace(s, @"<(.|\n)*?>", string.Empty).Equals(target)).ToArray();
Danasegarane Arunachalam replied to goldy gupta
First you should under stand something. I am helping and you cannot use that kind word.
You should first tell your requirement clearly.
Here is the example
private void button1_Click(object sender, EventArgs e)
{
string[] arr = { "Kshama", "Kshms", "Kshamta", "<span>Gold</Sapn>", "Goldy", "Goldinjh" };
var results = arr.Where(s => CheckMatch(s)).ToArray();
}
private bool CheckMatch(string s)
{
var target = "Gold";
if (s.IndexOf(target) > 0)
{
return true;
}
else
{
return false;
}
}
Hope this helps
goldy gupta replied to Danasegarane Arunachalam
Ok sory for that and thabks for your support
The code which you given me helps me in finding 'Gold' but its not finding Goldy when i set target = Goldy
goldy gupta replied to Danasegarane Arunachalam
Danasegarane Arunachalam replied to goldy gupta
I think the issue is with the .index of the method, It is not find the whole words
And in the below example I have used the Regular expression
private void button1_Click(object sender, EventArgs e)
{
string[] arr = { "Kshama", "Kshms", "Kshamta", "<span>Gold</Sapn>", "Goldy", "Goldinjh" };
var results = arr.Where(s => CheckMatch(s)).ToArray();
}
private bool CheckMatch(string s)
{
//var target = "Goldy";
var target = string.Format("{0}Gold{0}","\\b");
//var target = string.Format("{0}Goldy{0}", "\\b");
if (System.Text.RegularExpressions.Regex.IsMatch(s,target)==true )
{
return true;
}
else
{
return false;
}
}
And this worked for me in Gold and Goldy also
\\b in the pattern means find the whole word and the addition \ is the escape charter
goldy gupta replied to Danasegarane Arunachalam
That works for me Thanks and sorry If i said anything wrong... Thanks so much
Net hi friends Any one send frequently asked Important questions in C# .Net, ADO .Net, Asp .Net and Sql Server. . . . . . . . tx in Advance. . . . . . Hi, Find this. . (B)What is an IL? (B A) What is scavenging? (B) What are different types of caching using cache object of ASP.NET? (B) How can you cache different version of same page using ASP.NET cache object? (A) How will implement Page Fragment Caching? (B) Can you compare ASP.NET sessions with classic ASP? (B) Which are the various modes of storing ASP.NET session
in Sql server as var_name int How do you separate business logic while creating an ASP.NET application? There are two level of asp.net debugging 1. Page level debugging For this we have to edit the page level debugging The control itself will take care of the date display How can you deploy an asp.net application ? You can deploy an ASP.NET Web application using any one of the following three deployment options. a) Deployment using VS
Migration from ASP to ASP.net How to convert ASP site to ASP.NET site using C# http: / / www.asp.net / downloads / archived-v11 / migration-assistants / asp-to-aspnet hi, ASP.NET framework is very much different from unstrucured ASP and there is no correct way to
Tracing in ASP.NET? hi all, what is tracing? how to achieve tracing in asp.net? different ways of doing tracing? thanks and regards Aman Khan hi. . Tracing in ASP.NET 2.0 Tracing is a way to monitor the execution of your ASP.NET application. You can record exception details and program flow in a way that doesn't
using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Net; using System.Net.Mail; using namespace Email { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void send_Click(object sender, EventArgs e) { / / Code Statements / / replace xyz@xyz.com, zzz@xyz.com & xxxxx with actual values. try Net.Security.RemoteCertificateValidationCallback(Util.RemoteCertificateValidationCallback); And have the callback do something like this: static public bool RemoteCertificateValidationCallback(Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; } Which basically says: Accept A string containing the email address to certify < / param> / / / <returns> True of False< / returns> protected bool CertifiedEmail( string email) { Regex re = new Regex(@ " \ w. \ w@{1, 1} \ w[. \ w]?. \ w" ); return re.IsMatch(email); } / / Member Variables System.Net.NetworkCredential userCred = new System.Net.NetworkCredential(); protected string account; protected string subject; protected string to; protected string cc; protected string bcc; protected AttachmentCollection attachments; protected bool ssl; protected int port; / / Private Member Variables SmtpClient smtpClient = new SmtpClient(); MailMessage mail = new MailMessage Event delegates public delegate void MailSentEventHandler( object sender, MailSentEventArgs e); public event MailSentEventHandler OnMailSent; / / Flags bool sendActive = false ; / / Exception workarround variables System.ComponentModel.BackgroundWorker backgroundAsync = new System.ComponentModel.BackgroundWorker(); / / Properties / / / <summary