Q:

How to replace part of Connection String?

I'm using c# and I need to replace a string with other data.
This is the string, the servername, user1 and 380kj data and length can change.
"Data Source=servername;User ID=user1;Password=380kj"

I want this result:
"Data Source=servername;User ID=XXXXX;Password=XXXXX"

I have done an IndexOf on User ID and Password but I don't know how to get the exact count to use the remove function so I can then insert the XXXXX into the string.
   int index = SaleDatabase.ConnectionString.IndexOf("User ID=");
   int index2 = SaleDatabase.ConnectionString.IndexOf(";Password");

What can I do?
thanks...

A:

You can use the String.Replace method, but it seems that in your case you are editing a database connection string, in which case you should use the specific ConnectionStringBuilder for that connection string, such as: 
string connStr = "Data Source=servername;User ID=user1;Password=380kj";
System.Data.SqlClient.SqlConnectionStringBuilder sb = new System.Data.SqlClient.SqlConnectionStringBuilder(connStr);
sb.UserID = "XXXXX";
sb.Password = "XXXXX";
connStr = sb.ToString();

