This article mainly introduces the relevant information of C# retrieval case-insensitive and highlighted examples. Friends in need can refer to
C# retrieval insensitive Detailed explanation of case and highlight display examples
Today, I encountered a problem: How to highlight case-insensitive keywords in a web page
For example: text abcaBcabCaBCabcaBCa, keyword bc, in case of insensitivity, there are 6 matches in total.
What is displayed on the web page is abcaBcabCaBCabcaBCa.
Many people think of the replace function. But in c# the replace function cannot solve the letter case problem.
For example, bc, Bc, bC, and BC have all been searched, but they cannot be replaced by a single text.
The above text is reproduced from the article of Daniel "Wancang Yimi" - -"Highlight case-insensitive keywords - ASP".
But his article was written in the ASP version, and today I am writing the C# version; let’s talk about the solution below.
Solution: Use IndexOf
## ''''''''''''''''''''''''‑‑‑‑‑‑‐‐‐‐‐‐‐‐‐‐‐‐‐ The index of the first occurrence in the object. Parameters
1 2 3 4 5 6 7 8 9 10 |
|
Code
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 |
|
The above is the detailed content of C# implements case-insensitive retrieval and highlighting sample code sharing. For more information, please follow other related articles on the PHP Chinese website!