0% found this document useful (0 votes)
39 views

Program Code: String Operation

The document describes a C# program that demonstrates various string operations like concatenation, insertion, removal, searching/replacing, and checking for palindromes. The program displays a main menu allowing the user to select an operation to perform on input strings. It then outputs the results of the selected operation such as the concatenated, inserted, removed, searched/replaced, or palindrome checked string.

Uploaded by

akash_gautam_2
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Program Code: String Operation

The document describes a C# program that demonstrates various string operations like concatenation, insertion, removal, searching/replacing, and checking for palindromes. The program displays a main menu allowing the user to select an operation to perform on input strings. It then outputs the results of the selected operation such as the concatenated, inserted, removed, searched/replaced, or palindrome checked string.

Uploaded by

akash_gautam_2
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

STRING OPERATION

PROGRAM CODE

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static string stconcat(string a,string b)
{
string c=string.Concat(a,b);
return(c);
}

public void stinsert(string a, string b,int n)


{
Console.Write("\n\tAltered String : ");
Console.Write(a.Insert(n, b));
}

public void palin(string a)


{
int i,j,Flag=0;
char[] b;
b=a.ToCharArray();
for (j=0,i = b.Length-1; i >=0; i--,j++)
{
if(b[j]!=b[i])
Flag=1;
}

if (Flag==0)
Console.Write("\n\tString is a Palindrome.");
else
Console.Write("\n\tString is Not a Palindrome.");
}

public void stsearch(string a, string b, string c)


{
int indx = a.IndexOf(b);
Console.WriteLine("\n\tFound at : " + indx);
string d = a.Replace(b, c);
Console.Write("\n\tAltered String : " + d);

1
STRING OPERATION

public void stremove(string a, int n,int m)


{
string c;
c = a.Remove(n,m);
Console.Write("\n\tAltered String : " + c );
}

static void Main(string[] args)


{
string ch="1";
string a,b,c;
int n,m;
Program ob = new Program();
Console.Clear();
while (ch != "6")
{
Console.Clear();
Console.WriteLine("\n\t\tMAIN MENU.\n");
Console.WriteLine("\n\t1.Concatenate the strings.\n");
Console.WriteLine("\n\t2.Insert a String into a String.\n");
Console.WriteLine("\n\t3.Remove Characters from a String.\n");
Console.WriteLine("\n\t4.Search and Replace a String.\n");
Console.WriteLine("\n\t5.Check for Palindrome.\n");
Console.WriteLine("\n\t6.Exit.\n");
Console.Write("\n\tEnter the Option : ");
ch = Console.ReadLine();
switch (ch)
{
case "1" : Console.Clear();
Console.Write("\n\tEnter First String : ");
a = Console.ReadLine();
Console.Write("\n\tEnter Second String : ");
b = Console.ReadLine();
c = stconcat(a, b);
Console.WriteLine("\n\tConcatenated String : " + c);
break;
case "2": Console.Clear();
Console.Write("\n\tEnter First String : ");
a = Console.ReadLine();
Console.Write("\n\tEnter Sub String : ");
b = Console.ReadLine();
Console.Write("\n\tEnter the Position : ");
n = int.Parse(Console.ReadLine());
ob.stinsert(a,b,n);
break;
case "3": Console.Clear();

2
STRING OPERATION

Console.Write("\n\tEnter String : ");


a = Console.ReadLine();
Console.Write("\n\tEnter the First Position : ");
n = int.Parse(Console.ReadLine());
Console.Write("\n\tEnter the Number of Characters to Delete : ");
m = int.Parse(Console.ReadLine());
ob.stremove(a,n,m);
break;
case "4": Console.Clear();
Console.Write("\n\tEnter String : ");
a = Console.ReadLine();
Console.Write("\n\tEnter the String to be Searched : ");
b = Console.ReadLine();
Console.Write("\n\tEnter the Correct String : ");
c = Console.ReadLine();
ob.stsearch(a, b,c);
break;
case "5": Console.Clear();
Console.Write("\n\tEnter String : ");
a = Console.ReadLine();
ob.palin(a);
break;
case "6" : Console.WriteLine("\n\n\tThanks for using the system...");
break;

}
Console.ReadLine();
}
}
}
}

3
STRING OPERATION

MAIN MENU.

1.Concatenate the strings.


2.Insert a String into a String.
3.Remove Characters from a String.
4.Search and Replace a String.
5.Check for Palindrome.
6.Exit.
Enter the Option : 1

Enter First String : Akash

Enter Second String : Gautam

Concatenated String : Akash Gautam

MAIN MENU.

1.Concatenate the strings.


2.Insert a String into a String.
3.Remove Characters from a String.
4.Search and Replace a String.
5.Check for Palindrome.
6.Exit.
Enter the Option : 2

Enter First String : Akash Gautam

Enter Sub String : Umesh

Enter the Position : 6

Altered String : Akash UmeshGautam

4
STRING OPERATION

OUTPUT

MAIN MENU.

1.Concatenate the strings.


2.Insert a String into a String.
3.Remove Characters from a String.
4.Search and Replace a String.
5.Check for Palindrome.
6.Exit.
Enter the Option : 1

Enter First String : Akash


Enter Second String : Gautam
Concatenated String : Akash Gautam

MAIN MENU.

1.Concatenate the strings.


2.Insert a String into a String.
3.Remove Characters from a String.
4.Search and Replace a String.
5.Check for Palindrome.
6.Exit.
Enter the Option : 2

Enter First String : Akash Gautam


Enter Sub String : Umesh
Enter the Position : 6
Altered String : Akash UmeshGautam

5
STRING OPERATION

MAIN MENU.

1.Concatenate the strings.


2.Insert a String into a String.
3.Remove Characters from a String.
4.Search and Replace a String.
5.Check for Palindrome.
6.Exit.
Enter the Option : 3

Enter String : I am Akash Gautam.


Enter the First Position : 5
Enter the Number of Characters to Delete : 4
Altered String : I am h Gautam.

MAIN MENU.

1.Concatenate the strings.


2.Insert a String into a String.
3.Remove Characters from a String.
4.Search and Replace a String.
5.Check for Palindrome.
6.Exit.
Enter the Option : 4

Enter String : Hello...I am Akash Gautam.


Enter the String to be Searched : Hello
Enter the Correct String : Hiii
Found at : 0
Altered String : Hiii...I am Akash Gautam.

6
STRING OPERATION

MAIN MENU.

1.Concatenate the strings.


2.Insert a String into a String.
3.Remove Characters from a String.
4.Search and Replace a String.
5.Check for Palindrome.
6.Exit.
Enter the Option : 5

Enter String : madam


String is a Palindrome.

MAIN MENU.

1.Concatenate the strings.


2.Insert a String into a String.
3.Remove Characters from a String.
4.Search and Replace a String.
5.Check for Palindrome.
6.Exit.
Enter the Option : 6

Thanks for using the system...

You might also like