Welcome to the MongoDB community forums! If your string is stored as “Hello I am Vinicius. \n I play for Real Madrid”, the expected output via Console.WriteLine() in your C# application should be exactly the same “Hello I am Vinicius. \n I play for Real Madrid”. This is because MongoDB is simply storing the string containing the literal (\n as two characters in the string). If you want C# to interpret this as a newline, you would have to manually replace the characters as follows in your application:
var formatted = retrievedString.Replace("\\n", "\n");
Console.WriteLine(formatted);
Additionally, this depends on how you’re storing the string in the database. E.g If you use the MongoDB .NET/C# driver to insert a string like this (E.g “Hello I am Palmer. \n I play for Chelsea.”), the \n is interpreted by C# as a newline character and the string stored in MongoDB will be with the actual line break (without the characters \n).
Hi, Thanks for your answer. I managed to solve this immediately after posting it here, I am new to community and I forgot to delete this post however I will leave this so that it is useful for others.
Yes, it totally depends on how the string is stored in the database. If “\n” is used, that should be replaced with “\n” within the C#. The other solution is to use “\n” directly in the database so that Reg.Replace(“\n”, “\n”) is not required in C#.