查找一段字符串中相同元素出现的次数
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 }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律