玖我壬晴吧 关注:9贴子:937
  • 6回复贴,共1

字符串题目

只看楼主收藏回复

蓝莲花 - 许巍


1楼2015-08-08 23:45回复
    /// <summary>
    /// 在一个字符串找到第一个只出现一次的字符
    /// </summary>
    /// <returns></returns>
    static string First(string str)
    {
    for (int i = 0; i < str.Length - 1; i++)
    {
    if (!str.Substring(i + 1, str.Length - i - 1).Contains(str.Substring(i, 1)) &&
    !str.Substring(0, i).Contains(str.Substring(i, 1)))
    {
    return str.Substring(i, 1);
    }
    }
    return string.Empty;
    }


    2楼2015-08-08 23:46
    收起回复
      /// <summary>
      /// 压缩字符串
      /// </summary>
      /// <param name="str"></param>
      /// <returns></returns>
      static string YaSuo(string str)
      {
      string forY = str + "0";
      string putValue = string.Empty;
      int upCount = 0;
      int count = 1;
      for (int i = 1; i < forY.Length; i++)
      {
      if (forY.Substring(i, 1) != forY.Substring(upCount, 1))
      {
      putValue += forY.Substring(upCount, 1) + count;
      upCount = i;
      count =1;
      }
      else
      {
      count++;
      }
      }
      return putValue;
      }


      3楼2015-08-08 23:47
      收起回复
        /// <summary>
        /// 翻转句子中单词顺序
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        static string Reverse(string str)
        {
        string[] array = str.Split(' ').ToArray();
        Array.Reverse(array);
        string value = string.Join(" ", array);
        return value;
        }


        4楼2015-08-09 00:19
        收起回复