zoukankan      html  css  js  c++  java
  • 以单词为单位对字符串进行翻转(用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();
  • 相关阅读:
    Linux命令之查看cpu个数_核数_内存总数
    Python文件操作大全,随机删除文件夹内的任意文件
    Python文件操作:同一个文件进行内容替换
    异步请求Python库 grequests的应用和与requests库的响应速度的比较
    查询MySQL某字段相同值得重复数据
    /var/redis/run/redis_6379.pid exists, process is already running or crashed的解决办法
    人工智能----TensorFlow开篇简介
    Centos6.5+Python2.7 +ffmpeg+opencv2自动安装脚本
    决策统计---指标六要素
    大数据应用分类
  • 原文地址:https://www.cnblogs.com/xiongxuanwen/p/1992394.html
Copyright © 2011-2022 走看看