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

  • 相关阅读:
    九度OJ 1035:找出直系亲属 (二叉树、递归)
    九度OJ 1034:寻找大富翁 (排序)
    九度OJ 1033:继续xxx定律 (基础题)
    九度OJ 1032:ZOJ (基础题)
    centos 6.4 安装mongodb
    数据校验工具类
    《 mongodb 学习 》java 基本操作
    《 mongodb 学习 》基本操作2
    《 mongodb 学习 》之基本操作
    《 mongodb 学习 》之安装篇
  • 原文地址:https://www.cnblogs.com/stulife/p/1783635.html
Copyright © 2011-2022 走看看