zifuc2.cs
资源名称:Visual.rar [点击查看]
上传用户:yiyuerguo
上传日期:2014-09-27
资源大小:3781k
文件大小:1k
源码类别:
C#编程
开发平台:
Others
- using System;
- using System.Collections;
- public class MyClass
- {
- public static void Main()
- {
- string s = " asdf fasdf fasdf ";
- Console.WriteLine("before:");
- Console.WriteLine(s);
- Space( ref s );
- Console.WriteLine("after:");
- Console.Write(s);
- Console.ReadLine();
- }
- private static void Space( ref string str )
- {
- //空格在字符串中所处在的位置
- int index = str.IndexOf(' ');
- if( index >= 0 && index <= str.Length-1 )
- {
- try
- {
- //分成前后两个部分进行字符串的缩减
- string start = str.Substring( 0, index ).Trim();
- string end = str.Substring( index+1, (str.Length-index-1 )).Trim();
- //递归处理前后两端
- Space( ref start );
- Space( ref end );
- //把递归后的前后两端累加起来
- str = start + end;
- }
- catch( Exception e )
- {
- Console.Write(e.Message);
- //RL();
- }
- }
- }
- }