七叶笔记 » golang编程 » 编程去除字符串中空格源代码:

编程去除字符串中空格源代码:

编程去除字符串中空格源代码:

 using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            char[] chr = textBox1.Text.ToCharArray();
            IEnumerator ichr = chr.GetEnumerator();
            StringBuilder strb = new StringBuilder();
            while(ichr.MoveNext())
            {
                string str = (char)ichr.Current != ' ' ? ichr.Current.ToString() : string.Empty;
                strb.Append(str);
            }
            textBox2.Text = strb.ToString();
        }
    }
}  

结语:喜欢的请关注收藏!

相关文章