score:-1
you can use the regex function as am using below:
"<div>hello</div><span>world</span>".replace(/<[^>]*>/g, '')
score:1
i think there is no easy answer in your case, but you have several possibilities. regex can be a simple solution if you do not want to get the full tags. a more deeper but more complex would be to use a package like htmlagilitypack to parse your mail.
here is an example of the regex :
var searchword = "strong";
var mail = "<strong>blablabla</strong><p>blabla strong blabla</p>";
var rgx = new regex($"(?!<){searchword}(?!>)"); // will match strong but not <strong> or <strong or strong>
if (rgx.ismatch(mail))
{
// do what you want
}
score:1
see if you can use free and open source htmlagilitypack through which you can first convert the html text to plain text and then apply the search criteria.
e.g.: var plaintextresult = htmlutilities.converttoplaintext(string html);
if(!string.isnullorwhitespace(searchtext))
{
bool containsresult = plaintextresult.contains(searchtext);
}
score:1
thanks to @amine and @lollmbaowtfidgafgtfoohwtbs, i figured out how to do this.
first, i created a sql function in my database that strips a given text:
create function [dbo].[ufnstriphtml] (@htmltext nvarchar(max))
returns nvarchar(max) as
begin
declare @start int
declare @end int
declare @length int
set @start = charindex('<',@htmltext)
set @end = charindex('>',@htmltext,charindex('<',@htmltext))
set @length = (@end - @start) + 1
while @start > 0 and @end > 0 and @length > 0
begin
set @htmltext = stuff(@htmltext,@start,@length,'')
set @start = charindex('<',@htmltext)
set @end = charindex('>',@htmltext,charindex('<',@htmltext))
set @length = (@end - @start) + 1
end
return ltrim(rtrim(@htmltext))
end
go
then i added a reference to that function in my dbcontext
:
[dbfunction("ufnstriphtml")]
public static string striphtml(string text)
{
throw new exception("not implemented");
}
and now i can use it in my linq to sql
query:
if (!string.isnullorwhitespace(searchtext))
{
query = query.where(ent => tgdbcontext.striphtml(ent.contents).contains(searchtext));
}
Source: stackoverflow.com
Related Query
- Searching for a text in a string property where the value is HTML
- Is there a Linq operation to retrieve specific items from a list of items where the item has a property value for a property which should be unique?
- Searching each property value of an IQueryable collection of T against the value of a search query. How do I test for NOT NULL and CONTAINS together?
- C# - code to order by a property using the property name as a string
- Using LINQ, can I verify a property has the same value for all objects?
- Expression to get LINQ with Contains to EF for SQL IN() where on entities child's property equals value
- Searching in text files for a keyword until a string is encountered
- The given value of type String from the data source cannot be converted to type int of the specified target column
- Where is the source for System.Linq.Enumerable.ToList()?
- C# Linq to XML getting the elements where value of name contains a specific string
- Where is the code for the EDML generated Models?
- Get the objects with the maximum value for a specific property from a list using LINQ
- Filtering an array of objects to remove the ones that don't have the greatest value of for a property
- How to check string for null and assign its value in the same line
- Why the extension method of where for LINQ in this code would print out a single number while it shouldn't print anything at all?
- Searching for an item in a list that's nested inside another list based on a property value in C# using LINQ?
- How to get the property from a list of object that is a string with the lowest numeric value
- Order a list by a string value with the same name as the property
- Using LINQ, where one object property has a value of x, how do I return the value in a different property
- Creating a Custom Predicate using a String Value for the Numeric Operand
- Get all properties of an object using reflection - but only the properties where the object has a value for them (not default value or null)
- Creating a dynamic EF filter that builds a LINQ Where equals/contains statement for any string entity property
- Search rows in list, where one field match any value out of the String Array
- Find a string in the list and change value of another property using linq (complicated)
- How to replace the Text value with another string inside SelectListItem or SelectList mvc3?
- Write html anchor text (with name / value pair) to a string
- List from aggregated duplicate objects where a string property concats the strings from the duplicate objects in C#
- How can I find the first items in a list with a different value for a property using Linq?
- List or Array of String Contain specific word in Html Source Code
- List of objects where the object contains an array - how to use LINQ to search through all objects for a value in that array
More Query from same tag
- How do I combine two Expressions?
- add MAX to existing criteria in LINQ query
- Custom sorting using LINQ and Function
- are these two linq expressions functionally equivalent?
- Use Separate Elements From XML File
- Union lists by content
- Why is DebuggerStepThrough ignored on linq statements?
- Why does .Where() with a Func parameter executes the query?
- How to use Select in linq
- 100% CPU, stuck on CreateDelegate and CerHashtable`2.get_Item
- skipWhile in LINQ is not working as excepted
- Linq To Entities Group By with multiple tables in key
- Can I access individual list item during LINQ Join?
- How to Implement a method that finds the largest value, given two arrays(String[], Float[])
- Chaining to a compiled query loses performance benefit
- Get records modified within the last year from current date
- EF Core (LINQ) - The Query expression could not be Translated
- WPF - Linq moved to constructor is causing null reference exception, how come?
- Get string range in Lambda Expression
- Getting Exception while accessing value of JToken - Cannot access child value on Newtonsoft.Json.Linq.JValue
- LINQ - How paginate with single linq query in LINQ/C#
- Is there a better way to group by multiple columns in vb.net
- Need help converting DataTable to XML VB.NET
- Failed to group by field a table
- IEnumerable<T> unknown type preserve class information
- Multiple Sum using Linq (lambda expression)
- Sum values on list sorted by Distinct C#
- MySql ORDER BY FIELD() in EntityFramework
- Modify the expression tree of IQueryable.Include() to add condition to the join
- Build list for WPF from LINQ query result