- private void btn_Click(object sender, EventArgs e)
- {
- string danWord = txtDan.Text;
- string lastWord = danWord.Substring(danWord.Length - 1);
- string fuWord = "";
- switch (lastWord)
- {
- case "s":
- case "x":
- case "o":
- fuWord = danWord + "es";
- break;
- case "y":
- fuWord = danWord.Replace('y', 'i') + "es";
- break;
- case "h":
- if (danWord.Substring(danWord.Length - 2) == "ch" || danWord.Substring(danWord.Length - 2) == "sh")
- {
- fuWord = danWord + "es";
- }
- else
- {
- fuWord = danWord + "s";
- }
- break;
- default:
- fuWord = danWord + "s";
- break;
- }
- txtFu.Text = fuWord;
- }
- #region 阻止不规范的输入 -txtDan_KeyPress
- private void txtDan_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (e.KeyChar < 97 || e.KeyChar > 122)
- {
- e.Handled = true;
- }
- if (e.KeyChar == 8 || e.KeyChar == 32)
- {
- e.Handled = false;
- }
- }
- #endregion
复制代码 看看这是不是你要的结果 |