本文URL:http://www.cnblogs.com/CUIT-DX037/p/6770535.html

实现字符串自增和自减运算:

1.数字从 0-9 变化;

2.字母从 A-Z、a-z 变化;

3.其它字符跳过;

4.以上变化依据其Ascii码值;

     /// <summary>
/// 字符串运算
/// </summary>
public class StringOperation
{ /// <summary>
/// 通过ASCII码值,对字符串自增1
/// </summary>
/// <param name="pStr">输入字符串</param>
/// <returns></returns>
public static string StringIncreaseOne(string pStr)
{
var vRetStr = pStr;
if ( == pStr.Length)
{
vRetStr = "";
}
else
{
// 将最后一个字符与之前的字符串分开
string vOtherStr = pStr.Substring(, pStr.Length - );
int vIntChar = (int)pStr[pStr.Length - ]; //转ASCII码值
if ( <= vIntChar && vIntChar <= ) //是数字(0 - 9)
{
vIntChar++; //自增1
if (vIntChar == ) // 进一位
{
vIntChar = ;
vOtherStr = StringIncreaseOne(vOtherStr);
}
}
else if ( <= vIntChar && vIntChar <= ) //是字母(A - Z)
{
vIntChar++; //自增1
if (vIntChar == )
{
vIntChar = ;
vOtherStr = StringIncreaseOne(vOtherStr);
}
}
else if ( <= vIntChar && vIntChar <= ) //是字母(a - z)
{
vIntChar++; //自增1
if (vIntChar == )
{
vIntChar = ;
vOtherStr = StringIncreaseOne(vOtherStr);
}
}
else // 其它字符 -> 跳过
{
vOtherStr = StringIncreaseOne(vOtherStr);
}
vRetStr = vOtherStr + (char)vIntChar;
}
return vRetStr;
} /// <summary>
/// 通过ASCII码值,对字符串自减1
/// </summary>
/// <param name="pStr">输入字符串</param>
/// <returns></returns>
public static string StringReducingOne(string pStr)
{
var vRetStr = pStr;
if ( == pStr.Length)
{
vRetStr = "";
}
else
{
string vOtherStr = pStr.Substring(, pStr.Length - );
int vIntChar = (int)pStr[pStr.Length - ]; //转ASCII码值
if ( <= vIntChar && vIntChar <= ) //是数字(0 - 9)
{
vIntChar--;
if (vIntChar == )
{
vIntChar = ;
vOtherStr = StringReducingOne(vOtherStr);
}
}
else if ( <= vIntChar && vIntChar <= ) //是数字(A - Z)
{
vIntChar--;
if (vIntChar == )
{
vIntChar = ;
vOtherStr = StringReducingOne(vOtherStr);
}
}
else if ( <= vIntChar && vIntChar <= ) //是数字(a - z)
{
vIntChar--;
if (vIntChar == )
{
vIntChar = ;
vOtherStr = StringReducingOne(vOtherStr);
}
}
else // 其它字符 -> 跳过
{
vOtherStr = StringReducingOne(vOtherStr);
}
vRetStr = vOtherStr + (char)vIntChar;
}
return vRetStr;
} /// <summary>
/// 通过ASCII码值,对字符串自增
/// </summary>
/// <param name="pStr">输入字符串</param>
/// <param name="pCount">自增个数</param>
/// <returns></returns>
public static string StringIncrease(string pStr, int pCount)
{
string vRetStr = pStr;
for (int i = ; i < pCount; i++)
{
vRetStr = StringIncreaseOne(vRetStr);
}
return vRetStr;
} /// <summary>
/// 通过ASCII码值,对字符串自减
/// </summary>
/// <param name="pStr">输入字符串</param>
/// <param name="pCount">自减个数</param>
/// <returns></returns>
public static string StringReducing(string pStr, int pCount)
{
string vRetStr = pStr;
for (int i = ; i < pCount; i++)
{
vRetStr = StringReducingOne(vRetStr);
}
return vRetStr;
} }

最新文章

  1. Oracle 用户、角色、权限(系统权限、对象权限)的数据字典表
  2. 由于客户端检测到一个协议错误 代码0x1104
  3. Java核心技术点之内部类
  4. 【leetcode】Remove Linked List Elements(easy)
  5. 关于为busybox设置setuid
  6. redhat6.3安装MySQL-server-5.6.13-1.el6.x86_64.rpm
  7. 关于MediaPlayer的详细介绍
  8. Couchbase之个人描述及入门示例
  9. windos多线程编程
  10. Spark 资源调度及任务调度
  11. php设计模式笔记--总结篇
  12. linux shell命令之 xargs
  13. Kali Linux NetHunter教程Kali NetHunter支持的设备和ROMs
  14. [转]PHP时区/MySql时区/Linux时区
  15. 好系统重装助手教你如何让win10系统快速开机
  16. PC机Win10声音问题两例处理办法
  17. str_replace使用
  18. boost 时间
  19. [真题] 一道 vsftp 运维题
  20. Mac 10.12安装截图工具Jietu

热门文章

  1. [原创] 新人分享--ORA-01012:not logged on的解决办法 [复制链接]
  2. javaScript之深度理解原型链
  3. Socket对象以及异常
  4. Fast Walsh–Hadamard transform
  5. 6、git和github
  6. ARC097D Equals
  7. Entity Framework Code-First(9.9):DataAnnotations - ForeignKey Attribute
  8. linux下sed批量替换文件内容
  9. How to install Samba server on Ubuntu 12.04
  10. dos下操作Mysql数据库