• 以单词为单位对字符串进行翻转(用C#编写,但不用其中的库函数)


    //以单词为单位对字符串进行翻转,先按照字母进行翻转,然后按照单词进行翻转             string str1 = "12345     67890";             string str2 = "";             string str3 = "";             for (int o = str1.Length - 1; o >= 0; o--)                 str2 += str1[o];//按字母翻转             char[] chArr = new char[str1.Length];             int i = 0;             int j = 0;             int index = 0;             while (index < str2.Length-1)             {                 if (str2[index] == ' ')                 {                     j = index - 1;                     while (i <= j)                     {                         chArr[i] = str2[j];                         chArr[j] = str2[i];                         i++;                         j--;                     }                     index++;                     i = index;                 }                 else                 {                     index++;                 }             }             if (index == str2.Length - 1)             {                 j = index;                 while (i <= j)                 {                     chArr[i] = str2[j];                     chArr[j] = str2[i];                     i++;                     j--;                 }             }             for (int k = 0; k < str2.Length; k++)                 str3 += chArr[k].ToString();//按照单词翻转             Console.WriteLine("The reverse letter by letter of   {0}   is   {1}", str1, str2);             Console.WriteLine("The reverse word by word of   {0}   is   {1}", str1, str3);             Console.ReadLine();
  • 相关阅读:
    iOS开发——keychain的使用
    iOS开发——策略模式
    iOS开发——MVC模式
    iOS开发——代理模式
    ExtjsCode_Test02Panel.js
    网站收藏
    关于ExtJs Form表单的赋值、获取、重置
    ExtJS分页start,limit,pageSize的研究
    使Grid可编辑
    如何禁用Grid中的ToolBar中的Button
  • 原文地址:https://www.cnblogs.com/xiongxuanwen/p/1992394.html
Copyright © 2020-2023  润新知