Separation of Lanthanides/ Lanthanides and Actinides
C# p6
1. Renas R. Rekany Object-Oriented-Programming L3B
1
String Functions Definitions
Clone() Make clone of string.
CompareTo()
Compare two strings and returns integer value as output.
It returns 0 for true and 1 for false.
Contains()
The C# Contains method checks whether specified
character or string is exists or not in the string value.
EndsWith()
This EndsWith Method checks whether specified
character is the last character of string or not.
Equals()
The Equals Method in C# compares two string and
returns Boolean value as output.
GetHashCode() This method returns HashValue of specified string.
GetType() It returns the System.Type of current instance.
GetTypeCode() It returns the Stystem.TypeCode for class System.String.
IndexOf()
Returns the index position of first occurrence of specified
character.
ToLower()
Converts String into lower case based on rules of the
current culture.
ToUpper()
Converts String into Upper case based on rules of the
current culture.
Insert()
Insert the string or character in the string at the specified
position.
IsNormalized()
This method checks whether this string is in Unicode
normalization form C.
LastIndexOf()
Returns the index position of last occurrence of specified
character.
Length It is a string property that returns length of string.
Remove()
This method deletes all the characters from beginning to
specified index position.
Replace() This method replaces the character.
Split() This method splits the string based on specified value.
StartsWith()
It checks whether the first character of string is same as
specified character.
Substring() This method returns substring.
ToCharArray() Converts string into char array.
Trim()
It removes extra whitespaces from beginning and ending
of string.
2. Renas R. Rekany Object-Oriented-Programming L3B
2
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string s,fn, ln;
fn = textBox1.Text;
ln = textBox2.Text;
s = comboBox1.Text;
switch (s)
{
case "Clone":
textBox3.Text=Convert.ToString( fn.Clone());
textBox4.Text=Convert.ToString(ln.Clone());
break;
case "CompareTo":
int b = fn.CompareTo(ln);
if (b == 0)
MessageBox.Show("False");
else if (b == 1)
MessageBox.Show("True");
break;
case "Contains":
MessageBox.Show(Convert.ToString( fn.Contains("W")));
break;
case "EndsWith":
MessageBox.Show(Convert.ToString( fn.EndsWith("d")));
break;
case "Equals":
MessageBox.Show(Convert.ToString( fn.Equals(ln)));
break;
case "GetHashCode":
textBox3.Text =Convert.ToString( fn.GetHashCode());
textBox4.Text =Convert.ToString( ln.GetHashCode());
break;
case "GetType":
3. Renas R. Rekany Object-Oriented-Programming L3B
3
textBox3.Text = Convert.ToString(fn.GetType ());
textBox4.Text = Convert.ToString(ln.GetType ());
break;
case "GetTypeCode":
textBox3.Text = Convert.ToString(fn.GetTypeCode ());
textBox4.Text = Convert.ToString(ln.GetTypeCode ());
break;
case "IndexOf":
textBox3.Text = Convert.ToString(fn.IndexOf("e"));
textBox4.Text = Convert.ToString(ln.IndexOf("o"));
break;
case "ToLower":
textBox3.Text = Convert.ToString(fn.ToLower());
textBox4.Text = Convert.ToString(ln.ToLower());
break;
case "ToUpper":
textBox3.Text = Convert.ToString(fn.ToUpper());
textBox4.Text = Convert.ToString(ln.ToUpper());
break;
case "Insert":
textBox3.Text = Convert.ToString(fn.Insert(0, "Hi "));
textBox4.Text = Convert.ToString(ln.Insert(0, " Hi "));
break;
case "IsNormalized":
MessageBox.Show(Convert.ToString(fn.IsNormalized()));
break;
case "LastIndexOf":
textBox3.Text = Convert.ToString(fn.LastIndexOf("o"));
textBox4.Text = Convert.ToString(ln.LastIndexOf("s"));
break;
case "Length":
textBox3.Text = Convert.ToString(fn.Length);
textBox4.Text = Convert.ToString(ln.Length);
break;
case "Remove":
textBox3.Text = Convert.ToString(fn.Remove(5));
textBox4.Text = Convert.ToString(ln.Remove(0,4));
break;
case "Replace":
textBox3.Text = Convert.ToString(fn.Replace("o", "*"));
textBox4.Text = Convert.ToString(ln.Replace("w", "*"));
break;
case "Split":
string[] split1 = fn.Split(new char[] { 'o' });
textBox3.Text = split1[0];
string[] split2 = ln.Split(new char[] { 'd' });
textBox4.Text = split2[1];
break;
case "StartsWith":
textBox3.Text=Convert.ToString(fn.StartsWith("O"));
4. Renas R. Rekany Object-Oriented-Programming L3B
4
textBox4.Text = Convert.ToString(ln.StartsWith("W"));
break;
case "SubString":
textBox3.Text = Convert.ToString(fn.Substring(2, 5));
textBox4.Text = Convert.ToString(ln.Substring(4, 5));
break;
case "ToCharArray":
char[] s1 = fn.ToCharArray();
char [] s2= ln.ToCharArray();
for (int i = 0; i < fn.Length; i++)
{
textBox3.Text = textBox3.Text + s1[i];
}
for (int i = 0; i < ln.Length ; i++)
{
textBox4.Text = textBox4.Text + s2[i];
}
break;
case "Trim":
textBox3.Text = Convert.ToString(fn.Trim());
textBox4.Text = Convert.ToString(ln.Trim(new char[] {'s'}));
break;
}
}
}
}