Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
491 views
in Technique[技术] by (71.8m points)

Replace "\" with "" in a string in C#

I still don't get how to do this. I saw many posts regarding this, but none of the solutions worked for me.

I have a string called "a\b". The result I need is "a". How is this done?

I have a text file which has a database connection string pointing to an instance called - ServerDbInstance

My aim is to do a string replace in the text file -- replace "ServerDbInstance" with another value, say "10.11.12.13, 1200".

So I have:

stringToBeReplaced = @"ServerDbInstance";
newString = @"10.11.12.13, 1200";

This is where the problem starts. My stringToBeReplaced will always be "Server\DbInstance", and when I search for this string in my text file, the search fails, as the text file doesn't have a string "Server\DbInstance"; instead it has only "ServerDbInstance". So how do change "Server\DbInstance" to "ServerDbInstance"?

question from:https://stackoverflow.com/questions/7482360/replace-with-in-a-string-in-c-sharp

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

Please log in or register to answer this question.

Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...