Palindrome String in Windows Store App

In my previous article I described Palindrome Numbers. But in this article I describe Palindrome Strings. So let us first of all understand what a Palindrome String is.

Palindrome String

A string that is equal to itself reversed is called a Palindrome String. Just like the Palindrome number.

Example: String nitin is equal to itself reversed.

Use the following procedure to create the Palindrome String app.

Step 1

First of all you have to create a new Windows Store Application using the following:

  • Open Visual Studio 2012
  • "File" -> "New" -> "Project..."
  • Choose "Template" -> "Visual C#" -> "Window Store app"
  • Choose "Blank App (XAML)" then rename the application

new-windows-store-app.jpg

Step 2

Write the following XAML code in "Mainpage.Xaml" (that is available in Solution Explorer):

<Page

    x:Class="palindrome_string.MainPage"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:local="using:palindrome_string"

    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

    mc:Ignorable="d">

 

    <Grid Background="Blue">

        <Grid.RowDefinitions>

            <RowDefinition Height="38*"/>

            <RowDefinition Height="23*"/>

            <RowDefinition Height="31*"/>

            <RowDefinition Height="20*"/>

            <RowDefinition Height="42*"/>

            <RowDefinition Height="614*"/>

        </Grid.RowDefinitions>

        <Grid.ColumnDefinitions>

            <ColumnDefinition Width="555*"/>

            <ColumnDefinition Width="106*"/>

            <ColumnDefinition Width="705*"/>

        </Grid.ColumnDefinitions>

        <TextBlock Text="Check String is Palindrome or not" FontFamily="Arial" FontSize="14" FontWeight="ExtraBold" Foreground="Red" Grid.Row="1" Grid.ColumnSpan="3" TextAlignment="Center"></TextBlock>

        <TextBlock Text="Enter String:" FontFamily="Arial" FontSize="15" FontWeight="ExtraBold" Foreground="Red" Grid.Column="1" Grid.Row="2"></TextBlock>

        <TextBox x:Name="Textbox1" Width="150" Height="32" VerticalAlignment="Top" Grid.Column="2" Grid.Row="2" HorizontalAlignment="Left" Grid.RowSpan="2" />

        <TextBlock Text="String is:" FontFamily="Arial" FontSize="15" FontWeight="ExtraBold" Foreground="Red" Grid.Column="1" Grid.Row="3"></TextBlock>

        <TextBlock x:Name="text2" FontFamily="Arial" FontSize="15" FontWeight="ExtraBold" Foreground="Red" Grid.Column="2" Grid.Row="2" Margin="5,0,667,0" Height="32" VerticalAlignment="Bottom" Grid.RowSpan="2" />

        <Button Content="Click" Click="Button1_click" Grid.Column="2" Grid.Row="4" FontSize="15" Foreground="Red" Background="Yellow" Width="100" Height="37" Margin="0,5,0,0" VerticalAlignment="Top"  />

    </Grid>

</Page>

 

Step 3

Now write the following C# code for the button within "Mainpage.Xaml.cs":

using System;

using System.Collections.Generic;

using System.IO;

using System.Linq;

using Windows.Foundation;

using Windows.Foundation.Collections;

using Windows.UI.Xaml;

using Windows.UI.Xaml.Controls;

using Windows.UI.Xaml.Controls.Primitives;

using Windows.UI.Xaml.Data;

using Windows.UI.Xaml.Input;

using Windows.UI.Xaml.Media;

using Windows.UI.Xaml.Navigation;

 

namespace palindrome_string

{

    public sealed partial class MainPage : Page

    {

        public MainPage()

        {

            this.InitializeComponent();

        }

        protected override void OnNavigatedTo(NavigationEventArgs e)

        {

        }

        private void Button1_click(object sender, RoutedEventArgs e)

        {

            string str = Textbox1.Text;

            string revstr = "";

            for (int i = str.Length - 1;i>=0 ; i--)

            {

                revstr = revstr + str[i];

            }

            if (str == revstr)

            {

                text2.Text = "Palindrome";

            }

            else

            {

                text2.Text = "Not Palindrome";

            }

        }

    }

}

 

Step 4

Now Run Your app.

run-palindrom-string-app.jpg

output-of-palindrome-string.jpg


Similar Articles