zoukankan      html  css  js  c++  java
  • 搜索结果格式化


            private string FormatContext(string SearchKeyWords, string AllWords)
            {
                string ResultWorlds = string.Empty;
                AllWords = Regex.Replace(Regex.Replace(AllWords, @"\[pic\].*?\[/pic\]", "", RegexOptions.IgnoreCase), @"<[^>]*>", "", RegexOptions.IgnoreCase).Trim();
                int WordsCount = AllWords.Length;
                if (AllWords.Contains(SearchKeyWords))
                {
                    if (WordsCount <= 100)
                    {
                        ResultWorlds = Regex.Replace(ResultWorlds, SearchKeyWords, "<em>" + SearchKeyWords + "</em>", RegexOptions.IgnoreCase);
                    }
                    else
                    {
                        ResultWorlds = AllWords.Substring(AllWords.IndexOf(SearchKeyWords));
                        if (ResultWorlds.Length > 100)
                        {
                            ResultWorlds = ResultWorlds.Substring(0, 97) + "...";
                            ResultWorlds = Regex.Replace(ResultWorlds, SearchKeyWords, "<em>" + SearchKeyWords + "</em>", RegexOptions.IgnoreCase);
                        }
                    }
                }
                else
                {
                    if (WordsCount <= 100)
                    {
                        ResultWorlds = AllWords;
                    }
                    else
                    {
                        ResultWorlds = AllWords.Substring(0, 97) + "...";
                    }
                }

                return ResultWorlds;
            }

  • 相关阅读:
    jupyter notebook 在mac OS上的安装
    spring cloud 学习(11)
    spring cloud 学习(10)
    spring-boot 速成(12)
    spring cloud 学习(9)
    java一些常用并发工具示例
    python语法相关---1、
    python语法相关---2、
    Python人工智能参考---感知器(神经元)
    网站部署测试---1、apache如何部署网站
  • 原文地址:https://www.cnblogs.com/stulife/p/1783635.html
Copyright © 2011-2022 走看看