Q:

Find and remove part of string and again add that part with new value

Below is my connection string which is used at so many places.
<add key="conString" value="Data Source=My-Pc;Initial Catalog=Db1;User ID=sdfsdf;Password=facebook"></add>

Now at first I want to remove initialcatalog part from the connection string along with the database and later on I want to add initialcatalog part with new database name.
Below is the code:
public void statistics()
{
   String connString = System.Configuration.ConfigurationManager.AppSettings["conString"];
   //here i want to remove this part :  Initial Catalog=Db1;
   connString = "Data Source=My-Pc;User ID=sdfsdf;Password=facebook";

   //Here I have lots of operation and after that I would like to add this part with new database name

   string newDb= "db2";
   //again add that part with new db :  Initial Catalog=Db2;
   connString = "Data Source=My-Pc;Initial Catalog=Db2;User ID=sdfsdf;Password=facebook";
}

A:

// initialize ConnectionStringBuilder like so:
String connString = System.Configuration.ConfigurationManager.AppSettings["conString"];

var builder = new ConnectionStringBuilder(connString);
// set initial catalog to other database: 
builder.InitialCatalog = "<otherDatabaseName>";
// retrieve new connectionstring
var newConnectionString = builder.ToString();

