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;
            }

  • 相关阅读:
    Retrofit2.0+OkHttp打印Request URL(请求地址参数)
    Java如何从HttpServletRequest中读取HTTP请求的body
    解决gradle:download特别慢的问题
    20180531
    20180531 运算符重载
    20180531 二叉树
    20180530
    20180529-2
    20180529-1
    20180529
  • 原文地址:https://www.cnblogs.com/stulife/p/1783635.html
Copyright © 2011-2022 走看看