Today, we will take a One Scenario for A Step-by-Step Guide: Adding Character in the Ascii Sequence to Your String Like a Pro
Eg:
Input :LAKSHMI
Output:LM AB KL ST HI MN IJ.
Here is a Code:
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 Eventprivate 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
private void button1_Click(object sender, EventArgs e)
{
textBox2.Text = FinalResult(textBox1);
}
Conclusion:
Thanks for your read this article.
{
textBox2.Text = FinalResult(textBox1);
}
Conclusion:
Thanks for your read this article.
No comments:
Post a Comment