winform學習日誌(二十九)----------根據標點符號分行,StringBuilder的使用;將字串的每個字元顛倒輸出,Reverse的使用

來源:互聯網
上載者:User

標籤:winform   style   blog   class   c   code   

一:根據標點符號分行,,代碼很簡單

二:代碼
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;namespace Lines{    public partial class Frm_Main : Form    {        public Frm_Main()        {            InitializeComponent();        }        private void btn_true_Click(object sender, EventArgs e)        {            StringBuilder P_stringbuilder = //建立字串處理對象                new StringBuilder(txt_string.Text);            for (int i = 0; i < P_stringbuilder.Length; i++)//開始迴圈                if (P_stringbuilder[i] == ‘,‘)//判斷是否出現(,)號                    P_stringbuilder.Insert(++i,//向字串內添加分行符號                        Environment.NewLine);            txt_Lines.Text = //得到分行後的字串                P_stringbuilder.ToString();            bool P_bl = "abc" == "abc";            MessageBox.Show(P_bl.ToString());        }    }}
 三:將字串的每個字元顛倒輸出,:

四:相關代碼
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;namespace ReverseStr{    public partial class Frm_Main : Form    {        public Frm_Main()        {            InitializeComponent();        }        private void txt_input_TextChanged(object sender, EventArgs e)        {            char[] P_chr=txt_input.Text.ToCharArray();//從字串中得到位元組數組            Array.Reverse(P_chr, 0, txt_input.Text.Length);//反轉位元組數組(對象字元數組,起始位置,反轉長度)            txt_output.Text = //將位元組數群組轉換為字串並輸出                new StringBuilder().Append(P_chr).ToString();        }    }}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.