Aim:-Source Code:-: 1. String Append
Aim:-Source Code:-: 1. String Append
Source code:-
1. string append
using System;
using System.Text;
namespace BuilderAppend
{
class Appender
{
static void Main(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:
namespace BuilderReplace
{
class Replacer
{
static void Main(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(Greeting);
Console.Read();
}
}
}
Output:-
Please Enter Your Name :
Ceccollege
Good Morning , Ceccollege
Now Enter nick name
College
Good Morning, College
3 string Copy
using System;
namespace StringCopy
{
class StringCopier
{
[STAThread]
static void Main(string[] args)
{
Console.WriteLine("An Example of String Copy");
Console.WriteLine("Type Some Text");
string inputText = Console.ReadLine();
string copiedText = string.Copy(inputText);
Output:-
An Example Of String Copy
Type Some Text
Cec college
using System;
namespace StringSplit
{
class StringSplitter
{
static void Main(string[] args)
{
string textOriginal = "Value 1, Value 2, Value 3";
Console.WriteLine("");
Console.WriteLine("\r\n\r\nNow rejoin the textarray
with a different delimiter:");
//now rejoin the array of strings
string newJoin = string.Join(":", textArray);
Console.WriteLine(newJoin);
Console.Read();
}
}
}
Output:-
An example of splitting a string:
The string to split: value1,value2 value3
Result :
Value1
Value2
Value3
Now rejoin the textarray with a different delimiter:
Value1 :value2:value3
5. string substring
using System;
namespace StringSubstring
{
class Substring
{
static void Main(string[] args)
{
Output:-
A Substring example:
String to be Searched :abcdefghijklmnop
Start Index:4
Length :3
Substring:efg