Today, I do not know which tendon is wrong. The disordered memory shows that the string in C # has the CharAt () method. Alas, I have to say that I have substituted this usage in java into C.
After the proof is absent, the head's thinking is severely frustrated. I am stubborn in doing things, so I won't give up without reaching my goal. Since there is no CharAt () method in C #, I will compile it for him.
C # has one extension method.
I used this method to compile a CharAt () method for string. The Code is as follows:
1 using System;
2
3 namespace zuo_Company {
4
5 public class TestMain {
6 static void Main (){
7 string str = "abcdefg ";
8 string n_str = str. CharAt (str. Length-1 );
9 Console. WriteLine (n_str );
10}
11}
12
13 public static class CharAtExtention {
14 public static string CharAt (this string s, int index ){
15 if (index> = s. Length) | (index <0 ))
16 return "";
17 return s. Substring (index, 1 );
18}
19}
20}
Some possible things were taken into consideration when making this method. For example, if the length of the entire string is exceeded, the extraction operation cannot be performed.