<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
public partial class Form1 : Form { public Form1() { InitializeComponent(); } public static string CNumToCh(string x) { //數位轉換為中文後的陣列 string[] num = new string[] { "零", "壹", "貳", "叄", "肆", "伍", "陸", "柒", "捌", "玖" }; //為數位位數建立一個位陣列 string[] digit = new string[] { "", "拾", "佰", "仟" }; //為數位單位建立一個單位陣列 string[] units = new string[] { "", ",萬,", ",億,", ",萬億," }; string returnValue = ""; //返回值 int finger = 0; //字元位置指標 int m = x.Length % 4; //取模 int k = 0; if (m > 0) k=x.Length / 4 + 1; else k=x.Length / 4; //外層迴圈,四位一組,每組最後加上單位: ",萬億,",",億,",",萬," for (int i = k; i > 0; i--) { int L = 4; if (i == k && m != 0) L = m; //得到一組四位數 string four = x.Substring(finger, L); int l = four.Length; //內層迴圈在該組中的每一位數上回圈 for (int j = 0; j < l; j++) { //處理組中的每一位數加上所在的位 int n = Convert.ToInt32(four.Substring(j, 1)); if (n == 0) { if (j < l - 1&& Convert.ToInt32(four.Substring(j + 1, 1)) > 0 && !returnValue.EndsWith(num[n])) returnValue += num[n]; } else { if (!(n == 1 && (returnValue.EndsWith(num[0]) | returnValue.Length == 0) && j == l - 2)) returnValue += num[n]; returnValue += digit[l - j - 1]; } } finger += L; //每組最後加上一個單位:",萬,",",億," 等 if (i < k) //如果不是最高位的一組 { if (Convert.ToInt32(four) != 0) //如果所有4位元不全是0則加上單位",萬,",",億,"等 returnValue += units[i - 1]; } else { //處理最高位的一組,最後必須加上單位 returnValue += units[i - 1]; } } return returnValue; } private void button1_Click(object sender, EventArgs e) { if (txtStr.Text.Trim() == "") { return; } else { if (txtStr.Text.Trim().Length > 16) { MessageBox.Show("數位金額太大!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { if (txtStr.Text.Trim().Substring(0, 1) == "0") { MessageBox.Show("請正確輸入金額!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { richTextBox1.Text = CNumToCh(txtStr.Text.Trim()); } } } } private void txtStr_KeyPress(object sender, KeyPressEventArgs e) { if((e.KeyChar!=8&&!char.IsDigit(e.KeyChar))&&e.KeyChar!=13) { MessageBox.Show("請輸入數位!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtStr.Text = ""; txtStr.Focus(); } } }
partial class Form1 { /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.label2 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label(); this.button1 = new System.Windows.Forms.Button(); this.richTextBox1 = new System.Windows.Forms.RichTextBox(); this.txtStr = new System.Windows.Forms.TextBox(); this.SuspendLayout(); // // label2 // this.label2.AutoSize = true; this.label2.Location = new System.Drawing.Point(17, 53); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(65, 12); this.label2.TabIndex = 8; this.label2.Text = "轉換結果:"; // // label1 // this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(17, 15); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(65, 12); this.label1.TabIndex = 7; this.label1.Text = "輸入數位:"; // // button1 // this.button1.Location = new System.Drawing.Point(329, 11); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(75, 23); this.button1.TabIndex = 5; this.button1.Text = "開始轉換"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // // richTextBox1 // this.richTextBox1.Location = new System.Drawing.Point(79, 53); this.richTextBox1.Name = "richTextBox1"; this.richTextBox1.Size = new System.Drawing.Size(325, 131); this.richTextBox1.TabIndex = 9; this.richTextBox1.Text = ""; // // txtStr // this.txtStr.Location = new System.Drawing.Point(79, 12); this.txtStr.Name = "txtStr"; this.txtStr.Size = new System.Drawing.Size(244, 21); this.txtStr.TabIndex = 6; this.txtStr.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtStr_KeyPress); // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(414, 196); this.Controls.Add(this.richTextBox1); this.Controls.Add(this.txtStr); this.Controls.Add(this.label2); this.Controls.Add(this.label1); this.Controls.Add(this.button1); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "Form1"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "數位大小寫轉換"; this.ResumeLayout(false); this.PerformLayout(); } #endregion private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label1; private System.Windows.Forms.Button button1; private System.Windows.Forms.RichTextBox richTextBox1; private System.Windows.Forms.TextBox txtStr; }
到此這篇關於C#實現數位轉換漢字的範例詳解的文章就介紹到這了,更多相關C#數位轉漢字內容請搜尋it145.com以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援it145.com!
相關文章
<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
综合看Anker超能充系列的性价比很高,并且与不仅和iPhone12/苹果<em>Mac</em>Book很配,而且适合多设备充电需求的日常使用或差旅场景,不管是安卓还是Switch同样也能用得上它,希望这次分享能给准备购入充电器的小伙伴们有所
2021-06-01 09:31:42
除了L4WUDU与吴亦凡已经多次共事,成为了明面上的厂牌成员,吴亦凡还曾带领20XXCLUB全队参加2020年的一场音乐节,这也是20XXCLUB首次全员合照,王嗣尧Turbo、陈彦希Regi、<em>Mac</em> Ova Seas、林渝植等人全部出场。然而让
2021-06-01 09:31:34
目前应用IPFS的机构:1 谷歌<em>浏览器</em>支持IPFS分布式协议 2 万维网 (历史档案博物馆)数据库 3 火狐<em>浏览器</em>支持 IPFS分布式协议 4 EOS 等数字货币数据存储 5 美国国会图书馆,历史资料永久保存在 IPFS 6 加
2021-06-01 09:31:24
开拓者的车机是兼容苹果和<em>安卓</em>,虽然我不怎么用,但确实兼顾了我家人的很多需求:副驾的门板还配有解锁开关,有的时候老婆开车,下车的时候偶尔会忘记解锁,我在副驾驶可以自己开门:第二排设计很好,不仅配置了一个很大的
2021-06-01 09:30:48
不仅是<em>安卓</em>手机,苹果手机的降价力度也是前所未有了,iPhone12也“跳水价”了,发布价是6799元,如今已经跌至5308元,降价幅度超过1400元,最新定价确认了。iPhone12是苹果首款5G手机,同时也是全球首款5nm芯片的智能机,它
2021-06-01 09:30:45