C# 按照单词反转字符串
来源:互联网 发布:上瘾网络剧15集未减版 编辑:程序博客网 时间:2024/05/21 15:42
///<summary>
///单词反转
///</summary>
///<param name="array">待反转的字符串</param>
///<returns>已反转的字符串</returns>
///<author>Max Su</author>
publicstaticstring ReverseWords(string array)
{
int arrLen = array.Length;
char[] strNew =newchar[arrLen + 1];
//全部反转
for (int index = 0; index < arrLen; index++)
{
strNew[index] = array[arrLen - 1 - index];
}
strNew[arrLen] =' ';//为了复原最后一个单词,添加一个辅助空格
int iStart = 0, iEnd = 0;
char tmpChar;
//复原单词
for (int Index = 0; Index < arrLen + 1; Index++)
{
//Index指向空格
if (strNew[Index] ==' ')
{
iEnd = Index - 1;
while (iStart < iEnd)
{
tmpChar = strNew[iStart];
strNew[iStart] = strNew[iEnd];
strNew[iEnd] = tmpChar;
iStart++;
iEnd--;
}
iStart = Index + 1;//跳过空格
}
elseif (strNew[Index] =='!' | strNew[Index] == ',' | strNew[Index] =='.' | strNew[Index] ==';')
{
iStart = Index + 1;//跳过标点
}
}
//合成字符串
array = string.Empty;
for (int index = 0; index < strNew.Length - 1; index++ )//去掉辅助的空格
{
array += strNew[index];
}
return array;
}
- C# 按照单词反转字符串
- 将字符串按照单词完全反转
- 按照单词反转句子
- 将字符串按照单词完全反转-大公司面试题
- 将字符串按照单词完全反转---公司面试题
- 字符串反转,单词反转
- 将字符串按照单词完全反转过来,如"abc"反转为"cba"
- 按单词反转字符串
- 字符串单词顺序反转
- 按单词反转字符串
- 按单词反转字符串
- 反转字符串中的单词
- 字符串中单词反转
- 字符串单词反转
- 字符串中单词反转
- alg : 字符串单词反转
- 按单词反转字符串
- 按单词反转字符串
- MVC中上传文件
- 驰骋工作流引擎ccflow常见问题
- Pentaho源代码阅读报告
- std::vector学习
- [编程之美]饮料供货
- C# 按照单词反转字符串
- C#中unsafe的使用
- : The response of the WebApplicationException cannot be utilized as the response is already committe
- c# winform实现网页上用户自动登陆(破解)
- Oracle的在线重定义表功能
- 做手机应用,免费反而比收费更挣钱?
- poj 3468 A Simple Problem with Integer
- Mondrian
- Oracle DB2