1.编写一个函数把一个整数的字符串表示形式转换为整数并返回。(功能等同int.Parse)。
2.编写一个函数整数的字符串表示形式转换为整数。(功能等同于int.ToString)。
3.编写一个函数实现对给定字符串的截取,并返回子串。(要求功能同string.SubString相同).
4.编写一个函数实现接受一个给定的字符串,然后返回一个同本字符串完全相同的新实例。(功能同string.Copy)。
5.编写一个函数,判断在一个字符串中是否包含另外一个字符串。(功能同string.Contains)。
6.编写一个函数,实现在给定的字符串的指定位置插入另一个字符串,并返回(功能同string.Insert)。
7.编写一个Concat函数,实现两个字符串的拼接并返回。
8.编写一个函数,从一个字符串中移除给定的字符,并返回结果。如 void MoveChars(string str, char[] c);
从str移除所有数组c中指定的字

解决方案 »

  1.   

    只给第一题答案。public static int MyIntegerParse(this string text)   
    {   
    text = text.PadLeft(10, '0');   
    if (text[0] < '0' || text[0] > '9' ||   
    text[1] < '0' || text[1] > '9' ||   
    text[2] < '0' || text[2] > '9' ||   
    text[3] < '0' || text[3] > '9' ||   
    text[4] < '0' || text[4] > '9' ||   
    text[5] < '0' || text[5] > '9' ||   
    text[6] < '0' || text[6] > '9' ||   
    text[7] < '0' || text[7] > '9' ||   
    text[8] < '0' || text[8] > '9' ||   
    text[9] < '0' || text[9] > '9')   
    {   
    throw new FormatException();   
    }   
    return (text[0] - '0') * 1000000000 +   
    (text[1] - '0') * 100000000 +   
    (text[2] - '0') * 10000000 +   
    (text[3] - '0') * 1000000 +   
    (text[4] - '0') * 100000 +   
    (text[5] - '0') * 10000 +   
    (text[6] - '0') * 1000 +   
    (text[7] - '0') * 100 +   
    (text[8] - '0') * 10 +   
    (text[9] - '0');   
    }  效率比系统的快30%
    详见:
    http://blog.csdn.net/wuyazhe/archive/2010/06/24/5692560.aspx
      

  2.   

    考虑 ASCII吗 或者 位运算 ?
      

  3.   

    string 扩展