C经常用到的几个截取字符串[文].pdfVIP

  • 2
  • 0
  • 约6千字
  • 约 7页
  • 2021-10-13 发布于福建
  • 举报
C#经常用到的几个截取字符串 C#几个经常用到的字符串的截取 string str=quot;123abc456quot;; int i=3; 1 取字符串的前 i 个字符 str=str.Substring(0,i); // or str=str.Remove(i,str.Length-i); 2 去掉字符串的前 i 个字符: str=str.Remove(0,i); // or str=str.Substring(i); 3 从右边开始取 i 个字符: str=str.Substring(str.Length-i); // or str=str.Remove(0,str.Length-i); 4 从右边开始去掉 i 个字符: str=str.Substring(0,str.Length-i); // or str=str.Remove(str.Length-i,i); 5 判断字符串中是否有 quot;abcquot; 有则去掉之 using System.Text.RegularExpressions; string str = quot;123abc456quot;; string a=quot;abcquot;; Regex r = new Regex(a); Match m = r.Match(str); if (m.Success) { // 下面两个取一种即可。 str=str.Replace(a,quot;quot;); Response.Write(str); string str1,str2; str1=str.Substring(0,m.Index); str2=str.Substring(m.Index+a.Length,str.Length-a.Length-m.Index); Response.Write(str1+str2); } 6 如果字符串中有 quot;abcquot; 则替换成 quot;ABCquot; str=str.Replace(quot;abcquot;,quot;ABCquot;); ************************************************ string str=quot;adcdefquot;; int indexStart = str.IndexOf(quot;dquot;); int endIndex =str.IndexOf(quot;equot;); string toStr = str.SubString(indexStart,endIndex-indexStart); c#截取字符串最后一个字符的问题 ! str1.Substring(str1.LastIndexOf(quot;,quot;)+1); C# 截取字符串最后一个字符 k = k.Substring(k.Length-1, 1); lt;table width=quot;1000quot; height=quot;250quot; border=quot;0quot;gt; lt;trgt; lt;td align=quot;centerquot; colspan=quot;5quot;gt; lt;font size=quot;+3quot; gt;lt;stronggt; 请 假 条 lt;/stronggt;lt;/fontgt;lt;hr color=quot;#000000quot; width=quot;500quot;gt;lt;hr color=quot;#000000quot; width=quot;500quot;gt;lt;/tdgt;lt;/trgt; lt;trgt;lt;td align=quot;rightquot;gt; 单 位 : lt;/tdgt;lt;tdgt;lt;input

文档评论(0)

1亿VIP精品文档

相关文档