1st Level | struct. Prog.
| Lab 2
Lab#2:Strings
Program#1: Write a C# program that concatenates Your Firstname and Lastname and
then prints your fullName inverted.
using System;
namespace invertedName
{
class Program
{
static void Main(string[] args)
{
string firstname, lastname;
[Link]("Plz Enter your FirstName: ");
firstname = [Link]();
[Link]("Plz Enter your LastName: ");
lastname = [Link]();
string Name = [Link](firstname," ", lastname);
[Link](Name);
[Link]("***Inverted Name**** : ");
for (int i = [Link] - 1; i >= 0; i--)
{
[Link](Name[i]);
}
}
}
}
Output:
Page | 1
1st Level | struct. Prog. | Lab 2
Program#2: Write a C# Code that accepts your National ID and then
prints the last four numbers.
using System;
namespace Mtable
{
class Program
{
static void Main(string[] args)
{
string NationalId;
[Link]("Plz Enter Your National ID: ");
NationalId = [Link]();
string Last4nums = [Link](10, 4);
[Link]("The last 4 nums are: {0}", Last4nums);
}
}
}
Output:
Page | 2
1st Level | struct. Prog. | Lab 2
Program#3: Write a C# code that produces the number of index of c# in the string “
Welcome to c# programming Language. ” , removes all its empty characters and finally
prints the size of the new string.
using System;
namespace index
{
class Program
{
static void Main(string[] args)
{
string str = "Welcome to c# programming Language. ";
int index = [Link]("c#");
string str1=[Link]("index of c# in \"Welcome to c# programming
Language. \" is : \n {0} ",index);
[Link](str1);
string emptychar= [Link](" ", "");
[Link]("My String without empty charactr : \n {0} ", emptychar);
[Link]("the size of empty string is : \n {0} ",
[Link]);
}
}
}
output:
Page | 3
1st Level | struct. Prog. | Lab 2
Program#4: Write a C# program to list all substrings in agiven string.
using System;
namespace substrings
{
class Program
{
static void Main(string[] args)
{
string substring;
string[] a = new string[5];
[Link]("Enter the String : ");
string value = [Link]();
[Link]("All Possible Substrings of the Given String are :");
for (int i = 1; i <= [Link]; i++)
{
for (int j = 0; j <= [Link] - i; j++)
{
substring = [Link](j, i);
a[j] = substring;
[Link](a[j]);
}
}
}
}
}
Output:
Page | 4