• 查找一段字符串中相同元素出现的次数


     1   System.IO.StreamReader sr = new System.IO.StreamReader(aHtmlFilePath);
     2                 var htmlText = sr.ReadToEnd();
     3                 if (htmlText.Contains("img"))
     4                 {
     5                     string text = "<![if !vml]>";
     6                     int index = 0;
     7                     int count = 0;
     8                     int startindex, endindex;
     9                     while ((index=htmlText.IndexOf(text,index))!=-1)
    10                     {
    11                         count++;
    12                         startindex = index + 12;
    13                         endindex = htmlText.IndexOf("<![endif]>", index);
    14                         pictures.Add(htmlText.Substring(startindex, endindex - startindex));
    15                         index = index + text.Length;
    16                     }
    17                 }
    18                 sr.Dispose();
    19                 sr.Close();
     1   if (wWriteText.ToString().Contains("src"))
     2                 {
     3                     string text = "</v:shape>";
     4                     string bitmap = "Bitmap";
     5                     string result = string.Empty;
     6                     int index = 0;
     7                     int count = 0;
     8                     int startindex = 0;
     9                     if (wWriteText.ToString().Contains(bitmap))
    10                         result = System.Text.RegularExpressions.Regex.Replace(wWriteText.ToString(), bitmap, "");
    11                     wWriteText.Clear();
    12                     wWriteText.Append(result);
    13 
    14                     while ((index = wWriteText.ToString().IndexOf(text, index)) != -1)
    15                     {
    16                         startindex = wWriteText.ToString().IndexOf(text,index);
    17                         wWriteText.Insert(startindex, pictures[count].ToString());
    18                         index = index + text.Length + pictures[count].Length;
    19                         count++;
    20                     }
    21                 }
     1   if (wWriteText.ToString().Contains("src"))
     2                 {
     3                     string text = "</v:shape>";
     4                     string bitmap = "Bitmap";
     5                     string result = string.Empty;
     6                     int index = 0;
     7                     int count = 0;
     8                     int startindex = 0;
     9                     if (wWriteText.ToString().Contains(bitmap))
    10                         result = System.Text.RegularExpressions.Regex.Replace(wWriteText.ToString(), bitmap, "");
    11                     wWriteText.Clear();
    12                     wWriteText.Append(result);
    13 
    14                     while ((index = wWriteText.ToString().IndexOf(text, index)) != -1)
    15                     {
    16                         startindex = wWriteText.ToString().IndexOf(text,index);
    17                         wWriteText.Insert(startindex, pictures[count].ToString());
    18                         index = index + text.Length + pictures[count].Length;
    19                         count++;
    20                         if (pictures.Count == 1)
    21                             break;
    22                     }
    23                 }
  • 相关阅读:
    有关TSQL的10个好习惯
    jQuery操作Select
    SQL Server 高性能写入的一些总结
    如何限制文本框只能输入数字,小数点,英文,汉字等各类代码(转载)
    补码、条件跳转指令
    Windows获取进程完整路径
    NumPy库
    WS_窗口风格常量
    C语言核心技术第一章
    Ubuntu安装搜狗输入法
  • 原文地址:https://www.cnblogs.com/zhao987/p/14885309.html
Copyright © 2020-2023  润新知