using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Collections; // 引用 IEnumerator


namespace Example42

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }


        private void button1_Click(object sender, EventArgs e)

        {

            char[] P_chr = textBox1.Text.ToCharArray();  //得到字符数组

            IEnumerator P_ienumerator_chr = P_chr.GetEnumerator();  //得到枚举器

            StringBuilder P_stringbuilder = new StringBuilder();    //创建stringbuilder类型

            while (P_ienumerator_chr.MoveNext())

            {

                P_stringbuilder.Append((char)P_ienumerator_chr.Current != ' ' ? P_ienumerator_chr.Current.ToString() : string.Empty);  //向 stringbuilder对象中添加非空格字符

            }

            textBox2.Text = P_stringbuilder.ToString();

        }

    }

}

posted on 2011-10-20 00:24  C#_初学者  阅读(278)  评论(0编辑  收藏  举报