I am creating a C# UWP application and I have noticed that the line feed (\n) character is missing from the output text when I enter it into a Textbox. When I press enter into my Textbox it produces CR+LF character (\r\n). what can I do to bring the textbox behavior to notice both CR+LF & LF. I have set AcceptReturn = "true" and I have even tried replacing \n with \r\n but that doesn't work either.
As #lindexi said the new TextBox used \r as line feed character in Windows 10 build 15063. If you want to bring the textbox behavior to notice both CR+LF & LF. You may handle it programmatically on KeyUp event. However the \n & \n\r will turn to \r automatically.
For example :
// original
MyTextBox.Text = "Nico Zhu \nzhuminghao\nwanglaoshi\r\n\rzhuzhuz\n";
// converted
MyTextBox.Text = "Nico Zhu \rzhuminghao\rwanglaoshi\r\rzhuzhuz\r"
For more please refer to UWP TextBox control giving unexpected results.
Related
So my current project is comming to an end.
But I have an issue, i need to get a selection from any window and insert that into my current method, and then paste a new string into the selection.
This means that if i mark the following "This is a simple line", and i press my shortcut, i want "This is a simple line" to go into my method, and transform the text to "This line is more advanced", when i press my global hotkey.
Currently the method takes a string and returns a string (So the method works fine), i just need for it to copy the selection, do the method and then paste the new text, when i use my shortcut.
Any ideas?
I've solved it, the "fix" was just to simulate/emulate the "ctrt + c" "ctrl + v" shortcut in the project. I've gotten my inspiration from: This youtube video. Big thanks to "Matthew Watson" for the suggestion
Clipboard.SetText(textBox1.Text); //To copy your text to your clipboard
Clipboard.GetText(); //To get your text from your clipboard
Credit: https://stackoverflow.com/a/10140582/12345062
I have a button in wpf that when clicked does the following:
Clipboard.SetText("a\u0000b")
When I try and paste the contents of the clipboard into notepad all i get is:
a
How can I get the entire string?
If I render this string in a wpf control, i see a[square thing]b. In other words, the view control does not terminate at a null unicode character.
I tried to find if you can copy text with NUL in Windows, and it presumably is not possible. Maybe you could temporarily replace NUL with some other character, which should never appear in any text you process (although it probably will one day, as Murphy's law states), then open the text file and convert all occurrences of this character back to NUL?
var text = "a\u0000b";
var textToCopy = text.Replace("\u0000", "\u3f45");
Clipboard.SetText(textToCopy);
// Next paste the contents to the file and reverse the replacement there
It is a workaround, but if you're the one using those text files, it might be worth a try.
How to print '\u2623' on console in c#. I tried with Console.OutputEncoding = Encoding.UTF8;. But it does not work. When I write Console.WriteLine("\u2623"); my output is ?(question mark)
Try adding this code
Console.OutputEncoding = System.Text.Encoding.Unicode
It's also possible that your choice of Console font does not support that particular character. Click on the Windows Toolbar Menu (icon like C:.) and select Properties -> Font. Try some other fonts to see if they display your character properly
I am trying to save the data in a TextArea into a column in my database.
Then retrieve the data i saved from the database into a label or div.
Using this in HTMl to save:
<textarea runat="server" id="TextArea1" cols="100" rows="10" ></textarea>
Using this in c# to save:
cmd2.Parameters.AddWithValue("#s_qualification", TextArea1.InnerText);
I dont have any problem saving.
But when i retrieve the data from the database, the data does not have any linebreaks.
test2.InnerText = myReader3["s_qualification"].ToString();
Edit: When i display the data in a text area, it displays fine but its not the way i want it to.. The text needs to displayed like a label as its for a profile page's description
ps: using visual studio 2010, c#
Sorry for the trouble, Everything fixed:
test2.InnerHtml = myReader3["s_qualification"].ToString().Replace(Environment.NewLine, "<br />");
I entered the following text into the text box:
This is a test of the line breaks to see if a text area actually include line breaks \n
or is is just a magic word wrapping that happens \n
and it needs to be done manually.
Where \n shows where I pressed the Enter key.
var myText = TextArea1.Text;
string newText = myText.Replace("\r\n", "<br/>");
Results in newText:
This is a test of the line breaks to see if a text area actually include line breaks <br/>or is is just a magic word wrapping that happens <br/>and it needs to be done manually.
So,
test2.InnerText = myReader3["s_qualification"].ToString().Replace("\r\n", "<br/>");
Should do it.
Probably you can not detect line breaks at while you visualize on
test2.InnerText = myReader3["s_qualification"].ToString();
instead you sholud try to visualize on
<textarea>your text</textarea>
Note: Jon \n\r Skeet will be displayed in one line on visual studio watch window but two lines on textarea
Much better approach (if you display text in a label) is this: assign this CSS to your label:
label{
white-space: pre-wrap;
}
Source:
www.w3schools.com/cssref/pr_text_white-space.asp
I'm using a webbrowser control. How can I move the insert position for an execCommand to the end of the word, that is currently selected?
Example:
| <- current caret position
Som|eword -> move -> Someword| -> execCommand executes after current word
What I want to do is insert a line without braking the word. What happens now is:
Somew|ord -> line
Somew
ord
What should happen is:
Somew|ord -> line
Someword
This is so hacky that I'm almost embarrassed to post it, but ... you can accomplish "Inserting a line without breaking the word" "using a webbrowser control" by doing something like
webBrowser1.Url =
new Uri("javascript:" +
"var tr=document.selection.createRange();" +
"tr.expand('word');" +
"tr.collapse(false);" +
// "tr.select();" // Necessary to actually move the caret
"tr.pasteHTML('<hr>');");
After the webbrowser has loaded the document that you want to manipulate, and the user has selected the text that they'd like to insert a line after. If you really need the caret moved as well, you'd need a tr.select() after the tr.collapse().
It doesn't use the execCommand though, so it may not be suitable for your purposes. Maybe someone else can figure out a way to make this a little cleaner...