欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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è)字符與之前的字符串分開
    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í)有所幫助,也希望大家多多支持腳本之家。

  • C#基于HttpWebRequest實(shí)現(xiàn)發(fā)送HTTP請(qǐng)求的方法分析

    C#基于HttpWebRequest實(shí)現(xiàn)發(fā)送HTTP請(qǐng)求的方法分析

    這篇文章主要介紹了C#基于HttpWebRequest實(shí)現(xiàn)發(fā)送HTTP請(qǐng)求的方法,結(jié)合實(shí)例形式分析了C#使用HttpWebRequest類與System.IO類實(shí)現(xiàn)發(fā)送HTTP請(qǐng)求相關(guān)操作技巧與注意事項(xiàng),需要的朋友可以參考下
    2019-02-02
  • C#?Winform實(shí)現(xiàn)復(fù)制文件顯示進(jìn)度

    C#?Winform實(shí)現(xiàn)復(fù)制文件顯示進(jìn)度

    這篇文章主要介紹了C#?Winform實(shí)現(xiàn)復(fù)制文件顯示進(jìn)度,用進(jìn)度條來(lái)顯示復(fù)制情況,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-07-07
  • C#中的multipart/form-data提交文件和參數(shù)

    C#中的multipart/form-data提交文件和參數(shù)

    這篇文章主要介紹了C#中的multipart/form-data提交文件和參數(shù),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-06-06
  • C# Windows API應(yīng)用之基于FlashWindowEx實(shí)現(xiàn)窗口閃爍的方法

    C# Windows API應(yīng)用之基于FlashWindowEx實(shí)現(xiàn)窗口閃爍的方法

    這篇文章主要介紹了C# Windows API應(yīng)用之基于FlashWindowEx實(shí)現(xiàn)窗口閃爍的方法,結(jié)合實(shí)例形式分析了Windows API函數(shù)FlashWindowEx的功能、定義及實(shí)現(xiàn)窗口閃爍的相關(guān)技巧,需要的朋友可以參考下
    2016-08-08
  • c#自定義泛型類的實(shí)現(xiàn)

    c#自定義泛型類的實(shí)現(xiàn)

    本篇文章是對(duì)c#中自定義泛型類的實(shí)現(xiàn)方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-05-05
  • C#實(shí)現(xiàn)根據(jù)給出的相對(duì)地址獲取網(wǎng)站絕對(duì)地址的方法

    C#實(shí)現(xiàn)根據(jù)給出的相對(duì)地址獲取網(wǎng)站絕對(duì)地址的方法

    這篇文章主要介紹了C#實(shí)現(xiàn)根據(jù)給出的相對(duì)地址獲取網(wǎng)站絕對(duì)地址的方法,涉及C#URL及字符串操作的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-03-03
  • 基于C#開發(fā)中的那些編碼問(wèn)題(詳談)

    基于C#開發(fā)中的那些編碼問(wèn)題(詳談)

    下面小編就為大家分享一篇基于C#開發(fā)中的那些編碼問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2017-11-11
  • C#窗體實(shí)現(xiàn)點(diǎn)餐系統(tǒng)

    C#窗體實(shí)現(xiàn)點(diǎn)餐系統(tǒng)

    這篇文章主要為大家詳細(xì)介紹了C#窗體實(shí)現(xiàn)點(diǎn)餐系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-08-08
  • 最新評(píng)論