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

  • 相关阅读:
    redis命令
    linux命令行任务管理
    tomcat修改内存
    Python调用shell
    取消myeclipse自动进入workspace
    解决Myeclipse编译不生成.class文件问题
    Manacher回文串算法学习记录
    青少年如何使用 Python 开始游戏开发
    对 Linux 专家非常有用的 20 个命令
    对中级 Linux 用户非常有用的 20 个命令
  • 原文地址:https://www.cnblogs.com/stulife/p/1783635.html
Copyright © 2011-2022 走看看