最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#字符串自增自減算法詳解

 更新時(shí)間:2017年08月14日 10:14:44   作者:云夢(mèng)鴻  
這篇文章主要為大家詳細(xì)介紹了C#字符串自增自減的算法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

C#實(shí)現(xiàn)字符串自增和自減運(yùn)算,供大家參考,具體內(nèi)容如下

1.數(shù)字從 0-9 變化;

2.字母從 A-Z、a-z 變化;

3.其它字符跳過(guò);

4.以上變化依據(jù)其Ascii碼值;

/// <summary>
 /// 字符串運(yùn)算
 /// </summary>
 public class StringOperation
 {


  /// <summary>
  /// 通過(guò)ASCII碼值,對(duì)字符串自增1
  /// </summary>
  /// <param name="pStr">輸入字符串</param>
  /// <returns></returns>
  public static string StringIncreaseOne(string pStr)
  {
   var vRetStr = pStr;
   if (0 == pStr.Length)
   {
    vRetStr = "1";
   }
   else
   {
    // 將最后一個(gè)字符與之前的字符串分開(kāi)
    string vOtherStr = pStr.Substring(0, pStr.Length - 1);
    int vIntChar = (int)pStr[pStr.Length - 1]; //轉(zhuǎn)ASCII碼值
    if (48 <= vIntChar && vIntChar <= 57) //是數(shù)字(0 - 9)
    {
     vIntChar++; //自增1
     if (vIntChar == 58) // 進(jìn)一位
     {
      vIntChar = 48;
      vOtherStr = StringIncreaseOne(vOtherStr);
     }
    }
    else if (65 <= vIntChar && vIntChar <= 90) //是字母(A - Z)
    {
     vIntChar++; //自增1
     if (vIntChar == 91) 
     {
      vIntChar = 65;
      vOtherStr = StringIncreaseOne(vOtherStr);
     }
    }
    else if (97 <= vIntChar && vIntChar <= 122) //是字母(a - z)
    {
     vIntChar++; //自增1
     if (vIntChar == 123)
     {
      vIntChar = 97;
      vOtherStr = StringIncreaseOne(vOtherStr); 
     }
    }
    else // 其它字符 -> 跳過(guò)
    {
     vOtherStr = StringIncreaseOne(vOtherStr);
    }
    vRetStr = vOtherStr + (char)vIntChar;
   }
   return vRetStr;
  }

  /// <summary>
  /// 通過(guò)ASCII碼值,對(duì)字符串自減1
  /// </summary>
  /// <param name="pStr">輸入字符串</param>
  /// <returns></returns>
  public static string StringReducingOne(string pStr)
  {
   var vRetStr = pStr;
   if (0 == pStr.Length)
   {
    vRetStr = "9";
   }
   else
   {
    string vOtherStr = pStr.Substring(0, pStr.Length - 1);
    int vIntChar = (int)pStr[pStr.Length - 1]; //轉(zhuǎn)ASCII碼值
    if (48 <= vIntChar && vIntChar <= 57) //是數(shù)字(0 - 9)
    {
     vIntChar--;
     if (vIntChar == 47)
     {
      vIntChar = 57;
      vOtherStr = StringReducingOne(vOtherStr);
     }
    }
    else if (65 <= vIntChar && vIntChar <= 90) //是數(shù)字(A - Z)
    {
     vIntChar--; 
     if (vIntChar == 64)
     {
      vIntChar = 90;
      vOtherStr = StringReducingOne(vOtherStr);
     }
    }
    else if (97 <= vIntChar && vIntChar <= 122) //是數(shù)字(a - z)
    {
     vIntChar--;
     if (vIntChar == 96)
     {
      vIntChar = 122;
      vOtherStr = StringReducingOne(vOtherStr);
     }
    }
    else // 其它字符 -> 跳過(guò)
    {
     vOtherStr = StringReducingOne(vOtherStr);
    }
    vRetStr = vOtherStr + (char)vIntChar;
   }
   return vRetStr;
  }

  /// <summary>
  /// 通過(guò)ASCII碼值,對(duì)字符串自增
  /// </summary>
  /// <param name="pStr">輸入字符串</param>
  /// <param name="pCount">自增個(gè)數(shù)</param>
  /// <returns></returns>
  public static string StringIncrease(string pStr, int pCount)
  {
   string vRetStr = pStr;
   for (int i = 0; i < pCount; i++)
   {
    vRetStr = StringIncreaseOne(vRetStr);
   }
   return vRetStr;
  }

  /// <summary>
  /// 通過(guò)ASCII碼值,對(duì)字符串自減
  /// </summary>
  /// <param name="pStr">輸入字符串</param>
  /// <param name="pCount">自減個(gè)數(shù)</param>
  /// <returns></returns>
  public static string StringReducing(string pStr, int pCount)
  {
   string vRetStr = pStr;
   for (int i = 0; i < pCount; i++)
   {
    vRetStr = StringReducingOne(vRetStr);
   }   
   return vRetStr;
  }
  


 }

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

沁水县| 丹巴县| 旺苍县| 毕节市| 万安县| 徐水县| 龙南县| 虹口区| 普陀区| 通辽市| 乌拉特中旗| 兖州市| 古浪县| 鸡西市| 沧州市| 正定县| 武陟县| 曲麻莱县| 石景山区| 台安县| 花莲县| 建平县| 疏附县| 盐边县| 始兴县| 衡南县| 沽源县| 合川市| 木兰县| 安顺市| 呼伦贝尔市| 开原市| 漠河县| 中阳县| 射洪县| 关岭| 德格县| 海伦市| 江口县| 遵化市| 正宁县|