• Embed Doc
  • Readcast
  • Collections
  • CommentGo Back
Download
Aim:-Demonstrate some basic string manipulation using both the String Builder
and String Classes
Source code:-
1. string append
usingSystem;
usingSystem.Text;
namespaceBuilderAppend
{
classAppender
{
static voidMain(string[] args)
{
Console.WriteLine("Please Enter Your Name:");
string Name =Console.ReadLine();
StringBuilder Greeting =new StringBuilder();
Greeting.Append("Good Morning");
if (Name.Length > 0)
{
Greeting.Append(", "+Name+"!");
}else
{
Greeting.Append("!");
}Console.WriteLine(Greeting);
Console.Read();
}
}
}Output:-
please Enter Your Name:
This is cec college
Good Morning, This is cec college
2. replace string
usingSystem;
usingSystem.Text;
namespaceBuilderReplace
{
classReplacer
{
static voidMain(string[] args)
{
Console.WriteLine("Please Enter Your Name:");
string Name =Console.ReadLine();
StringBuilder Greeting =new StringBuilder();
Greeting.Append("Good Morning!");
if (Name.Length > 0)
{
Greeting.Insert(12,", "+ Name);
}Console.WriteLine(Greeting);
Console.WriteLine("Now Enter a Nickname:");
string NickName =Console.ReadLine();
if(Name.Length > 0 && NickName.Length > 0)
{
Greeting.Replace(Name, NickName);
}Console.WriteLine(Greeting);
Console.Read();
}
}
}Output:-

Please Enter Your Name :
Ceccollege
Good Morning , Ceccollege
Now Enter nick name
College
Good Morning, College

3 string Copy
usingSystem;
namespaceStringCopy
{
classStringCopier
{
[STAThread]
static voidMain(string[] args)
{
Console.WriteLine("An Example of String Copy");
Console.WriteLine("Type Some Text");
string inputText =Console.ReadLine();
string copiedText = string.Copy(inputText);
copiedText+=" more text";
Console.WriteLine("Your text is here: "+inputText);
Console.WriteLine("Copy of your text with some
additions: "+copiedText);
Console.Read();
}
}
}Output:-
An Example Of String Copy
Type Some Text
Cec college
Your text hear:ceccollege
Copy of your text with some addition :ceccollege more text
of 00

Leave a Comment

You must be to leave a comment.
Submit
Characters: ...
You must be to leave a comment.
Submit
Characters: ...