Short question: I have a string in my resources: "This is my test string {0}\n\nTest"
I'm trying to display this string in my Messagebox:
MessageBox.Show(String.Format(Properties.Resources.About,
Constants.VERSION),
Properties.Resources.About_Title, MessageBoxButton.OK,
MessageBoxImage.Information);
However I don't get new lines. The \n still show up as characters, not as new lines.
I also tried to use a workaround like mystring.Replace("\n", Environment.NewLine) but this also doesn't change anything.
What am I doing wrong?
Edit: Funny thing to mention: Replace("\n", "somethingelse") doesn't change anything.
Edit2: Shift+Enter in my Resource-File instead of \n seems to work... Strange behaviour anyway
Put a place holder where you want to put new line and in the code where you use that resource string, just replace it with new line: string resource: "This is first line.{0}This is second line.{0}This is third line." You will use this resource string like this: MessageBox.Show(string.Format(MyStringResourceClass.MyStringPropertyName, Environment.NewLine));
OR
Unconventional Method But i just now got it working by coping newline from word directly (or anyother place) & pasting it inside the resource string file.
It was simple..
OR
\r\n characters will be converted to new line when you display it by using message box or assign it to text box or whenever you use it in interface.
In C# (like most C derived languages), escape characters are used to denote special characters such as return and tab, and + is used in place of & for string concatenation.
To make your code work under C# you’ve got two options... the first is to simply replace the NewLine with the return escape character \n ala:
MessageBox.Show("this is first line" + "\n" + "this is second line");
The other method, and more correct is to replace it instead with Environment.NewLine which theoretically could change depending on the system you are using (however unlikely).
MessageBox.Show("this is first line" + Environment.NewLine + "this is second line");