09 August 2014

Add character in the ascii sequence

Today, we will take a One Scenario for  add character in the ascii sequence to a given string immediately after every character.
Eg:
   Input :LAKSHMI
  Output:LM AB KL ST HI MN IJ.
Here is a Code:
#region Declaration
private string _addValue = string.Empty;
private string _result = string.Empty;
private string _res = string.Empty;
#endregion
 #region Functions
private string AddValues(string c)
{
switch (c)
{
case "A": _addValue = "AB";
break;
 case "B": _addValue = "BC";
 break;
case "C":
 _addValue = "CD";
break;
case "D":
_addValue = "DE";
break;
case "E":
 _addValue = "EF";
break;
case "F":
_addValue = "FG";
break;
case "G":
 _addValue = "GH";
break;
case "H":
 _addValue = "HI";
break;
case "I":
 _addValue = "IJ";
 break;
case "J":
_addValue = "JK";
 break;
case "K":
_addValue = "KL";
break;
case "L":
 _addValue = "LM";
break;
case "M":
_addValue = "MN";
break;
case "N":
_addValue = "NO";
break;
case "O":
_addValue = "OP";
 break;
case "P":
 _addValue = "QR";
break;
case "R":
_addValue = "RS";
break;
case "S":
_addValue = "ST";
 break;
case "T":
 _addValue = "TU";
break;
 case "U":
 _addValue = "UV";
 break;
 case "V":
 _addValue = "VW";
break;
case "W":
 _addValue = "WX";
break;
case "X":
_addValue = "XY";
break;
case "Y":
_addValue = "YZ";
break;
case "Z":
_addValue = "ZA";
 break;
 }
return _addValue;
}
private string FinalResult(TextBox txt)
{
String str = Convert.ToString(txt.Text);
 char[] szArr = str.ToCharArray();
 for (int idx = 0; idx < szArr.Length; idx++)
{
_result = AddValues(Convert.ToString(szArr[idx]));
if (_res == string.Empty)
{
_res = _result;
}
else
{
_res = _res + " " + _result;
 }
 }
 return _res;
}
 #endregion
Call this function in Button Click Event
private void button1_Click(object sender, EventArgs e)
{
textBox2.Text = FinalResult(textBox1);
}
Conclusion:
   Thanks for your read this article.

No comments: