日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
C#數(shù)組和串操作經(jīng)驗總結(jié)

C#數(shù)組有很多值得學(xué)習(xí)的地方,這里我們主要介紹存放字符序列的C#數(shù)組,包括介紹C#串操作等方面

旌德網(wǎng)站制作公司哪家好,找創(chuàng)新互聯(lián)公司!從網(wǎng)頁設(shè)計、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、成都響應(yīng)式網(wǎng)站建設(shè)公司等網(wǎng)站項目制作,到程序開發(fā),運營維護。創(chuàng)新互聯(lián)公司于2013年開始到現(xiàn)在10年的時間,我們擁有了豐富的建站經(jīng)驗和運維經(jīng)驗,來保證我們的工作的順利進行。專注于網(wǎng)站建設(shè)就選創(chuàng)新互聯(lián)公司。

關(guān)于C#數(shù)組和C#串操作:
1)串是由連續(xù)存儲的字符組成
2)C#中的串具有恒定不變的特性,即 一旦被創(chuàng)建,就不能改變長度或者改變其中任何的字符。
3)串的連接、插入和刪除等操作都是生成了新串而沒有改變原串。
4)繼承自 System.object。所以是引用類型(int,bool,char 等都是struct 不是class,是值類型)。
5)System.String 是密封類,所以不能被繼承。
6)雖然System.String 是引用類型,但C#中將String 看作是基元類型,所以不用 new操作符創(chuàng)建實例,而是使用字符串駐留的機制。
7)System.String 繼承自 IComparable, ICloneable, IConvertible, IComparable , IEnumerable , IEnumerable, IEquatable 。
8)C#提供了StringBuilder類型來支持高效地動態(tài)創(chuàng)建字符串。

下面是自定義一個string類,類中包含一個字段,用以存放字符序列的C#數(shù)組,還有一些常用的C#串操作。

 
 
 
  1. public class StringDS
  2. {
  3. private char[] data;//char數(shù)組
  4. //索引器
  5. public char this[int index]
  6. {
  7. get 
  8. {
  9. return data[index];
  10. }
  11. set
  12. {
  13. data[index] = value;
  14. }
  15. }
  16. //構(gòu)造函數(shù)
  17. public StringDS(char[] arr)
  18. {
  19. data = new char[arr.Length];
  20. for (int i = 0; i < arr.Length; i++)
  21. {
  22. data[i] = arr[i];
  23. }
  24. }
  25. //構(gòu)造函數(shù) 
  26. public StringDS(int len)
  27. {
  28. char[] arr = new char[len];
  29. data = arr;
  30. }
  31. //求串長 
  32. public int GetLength()
  33. {
  34. return data.Length;
  35. //串比較 
  36. public int Compare(StringDS s) 
  37. {
  38. int len=((this.GetLength()<=s.GetLength())? 
  39. this.GetLength():s.GetLength()); 
  40. int i = 0; 
  41. for (i = 0; i < len; ++i) 
  42. if (this[i] != s[i]) 
  43. break; 
  44. if (i <= len)
  45. {
  46. if (this[i] < s[i])
  47. {
  48. return -1;
  49. }
  50. else if (this[i] > s[i])
  51. {
  52. return 1;
  53. }
  54. }
  55. else if (this.GetLength() == s.GetLength())
  56. {
  57. return 0;
  58. }
  59. else if (this.GetLength() < s.GetLength())
  60. {
  61. return -1;
  62. }
  63. return 1;
  64. //求子串 
  65. public StringDS SubString(int index, int len) 
  66. if ((index<0) || (index>this.GetLength()-1) || (len<0) || (len>this.GetLength()-index)) 
  67. Console.WriteLine("Position or Length is error!"); 
  68. return null; 
  69. StringDS s = new StringDS(len); 
  70. for (int i = 0; i < len; ++i) 
  71. s[i] = this[i + index-1]; 
  72. return s; 
  73. //串連接 
  74. public StringDS Concat(StringDS s)
  75. {
  76. StringDS s1 = new StringDS(this.GetLength() +s.GetLength());
  77. for (int i = 0; i < this.GetLength(); ++i)
  78. {
  79. s1.data[i] = this[i];
  80. }
  81. for (int j = 0; j < s.GetLength(); ++j)
  82. {
  83. s1.data[this.GetLength() + j] = s[j];
  84. }
  85. return s1;
  86. //串插入 
  87. public StringDS Insert(int index, StringDS s) 
  88. int len = s.GetLength(); 
  89. int lenlen2 = len + this.GetLength(); 
  90. StringDS s1 = new StringDS(len2); 
  91. if (index < 0 || index > this.GetLength() - 1) 
  92. Console.WriteLine("Position is error!"); 
  93. return null; 
  94. for (int i = 0; i < index; ++i) 
  95. s1[i] = this[i]; 
  96. for(int i = index; i < index + len ; ++i) 
  97. s1[i] = s[i - index]; 
  98. for (int i = index + len; i < len2; ++i) 
  99. s1[i] = this[i - len]; 
  100. }
  101. return s1;
  102. }
  103. //串刪除 
  104. public StringDS Delete(int index, int len)
  105. {
  106. if ((index < 0) || (index > this.GetLength() - 1)
  107. || (len < 0) || (len > this.GetLength() - index))
  108. {
  109. Console.WriteLine("Position or Length is error!");
  110. return null;
  111. }
  112. StringDS s = new StringDS(this.GetLength() - len);
  113. for (int i = 0; i < index; ++i)
  114. {
  115. s[i] = this[i];
  116. }
  117. for (int i = index + len; i < this.GetLength(); ++i)
  118. {
  119. s[i] = this[i];
  120. }
  121. return s;
  122. //串定位 
  123. public int Index(StringDS s) 
  124. if (this.GetLength() < s.GetLength()) 
  125. Console.WriteLine("There is not string s!"); 
  126. return -1; 
  127.  
  128. int i = 0; 
  129. int len = this.GetLength() - s.GetLength(); 
  130. while (i < len
  131. if (this.Compare(s) == 0) 
  132. {
  133. break;
  134. }
  135. }
  136. if (i <= len)
  137. {
  138. return i;
  139. }
  140. return -1;
  141. }

文章名稱:C#數(shù)組和串操作經(jīng)驗總結(jié)
本文路徑:http://www.5511xx.com/article/djegoii.html