Answer the question
In order to leave comments, you need to log in
How to replace characters in a string using c#?
Guys, you need to change the characters (Words) in a string in c#
I use Replace :
string textFile = System.IO.File.ReadAllText(@"C:\Users\Александр\Desktop\good.htm");
textFile = textFile.Replace("datatimes", this.clientsItem.dateconnect.ToString());
File.AppendAllText(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\otchet.htm", textFile, System.Text.Encoding.GetEncoding("utf-8"));
Answer the question
In order to leave comments, you need to log in
I suspect that the problem is a case mismatch, i.e. in the text "DataTimes" and is replaced by "datatimes". If you need a case-insensitive replacement, you can use Regex.Replace:
Regex.Replace(textFile, "datatimes", this.clientsItem.dateconnect.ToString(), RegexOptions.IgnoreCase)
The funny thing is that if you assign a new variable, then everything is fine
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question