標籤: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(); } }}