Coding Challenge - ASP.NET Program : Given a string S, shift each character to its immediate right character (note: preserve the cases)
Write a ASP.NET with C# program to achieve the following
"Given a string Str, shift each character to its immediate right character (Main Criteria: preserve the cases)"
Sample input : HeLlo
Sample output : IfMmp
ShiftNext.aspx
<div>
<table>
<tr>
<td>Enter the string
</td>
<td>
<asp:TextBox ID="txtInputString" runat="server">
</asp:TextBox>
</td>
<td>
<asp:Button ID="btnShowResult" runat="server" OnClick="btnShowResult_Click" Text="Click for result" />
</td>
</tr>
<tr>
<td>The result is
</td>
<td>
<asp:Label ID="lblResult" runat="server"></asp:Label>
</td>
<td>
</td>
</tr>
</table>
</div>
C# (ShiftNext.aspx.cs)
protected void btnShowResult_Click(object sender, EventArgs e)
{
string inputStr =
txtInputString.Text.Trim();
string result = string.Empty;
char[] charArray =
inputStr.ToCharArray();
foreach (char singleChar in charArray)
{
bool
isCharUpper = char.IsUpper(singleChar);
char
tempChar;
if
(singleChar == 'Z' || singleChar == 'z')
{
tempChar = 'a';
if (isCharUpper) tempChar = 'A';
}
else
{
tempChar = (char)(singleChar + 1);
}
result += tempChar;
}
lblResult.Text = result;
}
Comments