12345678910111213141516171819202122232425262728293031323334353637383940 |
- @inherits FnzComponentBase
- @code {
- [Parameter, Required] public string Text { get; set; }
- [Parameter, Required] public IReadOnlyCollection<string> Keywords { get; set; }
- }
- @if (string.IsNullOrEmpty(Text) == false)
- {
- var lowerText = Text.ToLower();
- for (var index = 0; index < Text.Length; ++index)
- {
- bool match = false;
- foreach (var kw in Keywords.Where(p => string.IsNullOrEmpty(p) == false).OrderByDescending(p => p.Length))
- {
- match = true;
- var lowerKw = kw.ToLower();
- for (var ki = 0; ki < kw.Length; ++ki)
- {
- if (index + ki >= Text.Length || lowerText[index + ki] != lowerKw[ki])
- {
- match = false;
- break;
- }
- }
- if (match)
- {
- <span class="text-danger">@Text.Substring(index,kw.Length)</span>
- index += kw.Length - 1;
- break;
- }
- }
- if (index < Text.Length && match == false)
- {
- <span>@Text[index]</span>
- }
- }
- }
|