summary refs log tree commit diff
path: root/string_handling/StringHandling/frmMain.cs
diff options
context:
space:
mode:
author1970-01-01 00:00:00 +0000
committer2025-01-08 04:48:47 +0000
commitdd07406b85b2d162a1c4d42a2dd6867ca4ccf579 (patch)
tree8061bf2efa45fbeba4f64dd909d0c41f20174017 /string_handling/StringHandling/frmMain.cs
parentfuture value 4 (diff)
downloadcs-dd07406b85b2d162a1c4d42a2dd6867ca4ccf579.tar
cs-dd07406b85b2d162a1c4d42a2dd6867ca4ccf579.tar.gz
cs-dd07406b85b2d162a1c4d42a2dd6867ca4ccf579.tar.bz2
cs-dd07406b85b2d162a1c4d42a2dd6867ca4ccf579.tar.xz
cs-dd07406b85b2d162a1c4d42a2dd6867ca4ccf579.zip
string handling
Diffstat (limited to 'string_handling/StringHandling/frmMain.cs')
-rw-r--r--string_handling/StringHandling/frmMain.cs89
1 files changed, 89 insertions, 0 deletions
diff --git a/string_handling/StringHandling/frmMain.cs b/string_handling/StringHandling/frmMain.cs
new file mode 100644
index 0000000..3db9fec
--- /dev/null
+++ b/string_handling/StringHandling/frmMain.cs
@@ -0,0 +1,89 @@
+#nullable enable

+using System;

+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 StringHandling

+{

+	public partial class frmMain : Form

+	{

+		public frmMain()

+		{

+			InitializeComponent();

+		}

+

+		private void btnParseName_Click(object sender, System.EventArgs e)

+		{

+			// DONE: Add code to parse name

+			string fName = "";

+			string? mName = null;

+			string lName = "";

+

+			string name = txtFullName.Text.Trim();

+			string[] names = name.ToLower().Split(' ');

+

+			if (names.Length == 2) {

+				fName = names[0];

+				lName = names[1];

+			}

+			else if (names.Length == 3) {

+				fName = names[0];

+				mName = names[1];

+				lName = names[2];

+			}

+			else {

+				MessageBox.Show("You need to enter a full name "

+					+ "consisting of 2 or optionally 3 words",

+					"Error");

+				return;

+			}

+

+			string msg = "First name:\t" + ToInitialCap(fName)

+				+ "\n\nMiddle Name:";

+			if (mName != null)

+				msg += "\t" + ToInitialCap(mName);

+			msg += "\n\nLast name:\t" + ToInitialCap(lName);

+

+			MessageBox.Show(msg, "Parse Name");

+		}

+

+		private void btnEditPhoneNumber_Click(object sender, System.EventArgs e)

+		{

+			// DONE: Add code to edit the phone number

+			string phone = txtPhoneNumber.Text.Trim();

+

+			string digits = "";

+			foreach (char i in phone)

+				if (i >= '0' && i <= '9')

+					digits += i;

+

+			string standard = digits;

+			standard = standard.Insert(3, "-");

+			standard = standard.Insert(7, "-");

+

+			MessageBox.Show("Entered:\t\t"

+				+ phone + "\n\nDigits only:\t"

+				+ digits + "\n\nStandard format:\t"

+				+ standard, "Edit Phone Number");

+		}

+

+		// DONE: Add ToInitialCap method here

+		private string ToInitialCap(string s)

+		{

+			return s[0].ToString().ToUpper()

+				+ s.Remove(0, 1);

+		}

+

+		private void btnExit_Click(object sender, System.EventArgs e)

+		{

+			this.Close();

+		}

+

+	}

+}