How do i add a TAB (\t) to a string resource ?
"\tText" doesn't work
You have to explicitly add the tab in. The easiest way of doing this is probably to type out your string in notepad (with the tab explicitly set in place rather then using an escape character) and copy and paste the text into the resource editor.
You will have a similar problem with newlines, the easiest way of adding them in is to - again - add newlines in explicitly by using the shift-enter key combination.
You have two options that I am aware of:
Do a string replace after reading your resource string: s = s.Replace("\\t","\t");
Enter the escape sequence directly into your resource string at creation time by typing Alt-012 (I think that's tab) on the numeric keypad.
Articles on the same here and here.
Use the Alt Code for Tab (Alt + 009)
Newlines are added using Shift + Return.
1) Open up resources file in VS.
2) Put cursor where you want the Tab character
3) Hold down Alt key
4) Press 0, 0, 9 on the numeric keypad.
5) Let go alt key.
When you click off the resource string, you will see the tabs get removed from the display, rest assured they are still there. This can be verified by opening the Resources.Designer.cs and looking at the comment for the resource string and highlighting the area where the tab was inserted.
It's nearly six years since this thread was last modified, and the recommendation to use escapes still rules the day. For what it's worth, earlier today, I copied some text from a C# string constant into the resource string editor, and the tab got replaced by spaces. However, since the code expected to see the actual tab character, it threw an InvalidOperationException (my code, my exception!). Once again, I fell back to the tab, following the excellent instructions in the DevX article, "Another Way to Escape Sequences in .NET Resource Files," mentioned in the second citation in the accepted answer.
Moral: Don't count on the Windows Clipboard to faithfully copy your text.
Have you tried the XML tab character?
Sorry my tab character didn't show! Must have got eaten up by the browser.
\t does add an ascii tab but if you are displaying this in an html page you will not see that tab except in the page source. HTML doesn't render tabs or new-lines as non-breaking space. They all get reduced to 1 space character when displayed. Formatting HTML with whitespace is not recommended, that is what div with CSS or even Table are for. If you must add extra white space in HTML use the repeatedly but it will not be tab stop correct and will create a nightmare if you ever copy and paste.
Alternately you can display your string data in a read-only Text Area. This will preserve your string format. Without knowing the specifics of what you are trying to do with your string or how you are creating it these are the best suggestions I can give you.
You can also create a variable but the \t works inline.
string TAB = char.ConvertFromUtf32(9).ToString();
Related
OK. Simple as possible: I want to inject a RichTextFormat comment (e.g. '{\*\atnid 1}' into the RichTextBox.Rtf;. That command doesn't show up in the richtextbox display area, which is the way I want it. The trouble is, there's no way I can see to put that comment in using C# and .NET. Adding it as a string adds an extra backslash each time, since the backslash char is the escape char, and the RTB displays it.
How to get'{\*\atnid 1}' into the Rtf buffer without additional backslashes being added by .NET?
Need some HTML code for Escape characters that accepts and do its functionality in a TextBlock.
For Example:
for \n
My requirement is, I have a XML file which holds a field named Memo and it need to hold some text like in the below image
For CCJS, i need a tab to make it center. like wise the rest of text to be aligned.
XML tag:
memo="\tCCJS
\t==========
If the "CCJS" field is customized on the General Occurrence screen, then the same custamization should be made to the "CCJS Status" field on the conclusion block."
Above given is just for an example, I have more text like these so i need some set of HTML code to have all these Text accepted in xml and Textblock
I have gone through Here.. Still i dont found code for Tab. if i would get a full list of these codes, it would be helpful..
Thanks.
I've always just used the Line Feed character (which will work in xaml and is html encoded, it's also already included your example)
Dec. =
Hex. =
As example;
<TextBlock Text="Line One
Line Two"/>
Hope this helps.
PS - for your tabs, just get your spacing correct and utilize Preserve Whitespace / xml:space="preserve"
Problem:
My site allows users to copy/paste contents from other files/documents like MS Word and websites (eg CNN.com) into the Rich TextEditor we provide. This Rick TextEditor supports (and we too have to support) paste contents with embedded styles, this brings random styles, tags inline styles from content origin.
Eg: If you paste from any MS word document, it brings H1, H2, P, UL/OL/LI, STRONG, I, EM, TABLE etc. with their own styles. Same happens when you copy paste from other webpages.
How To Format?
I am looking for THE best way to handle the formatting of these kinds of user-generated contents. First, I need to keep the copied tags intact. Lets say, H1 was brought from user from MS Word - I have to keep this yet style on my own using given corporate branding.
Another problem is, when you copy/paste from external origin - some tags are not properly closed - this causes my layout break. How do we handle this?
For styles, m applying
.article * {
allKnownCSSProperties: myValues!important;
}
Any method would work. JavaScript, C# is preferred.
To strip out unwanted styles a simple regex would suffice. In Javascript:
/( style=['"][^'"]*['"])/g
I'd try to solve problem with lack of closed tags as this:
Parse whole message and collect tags that's not ends with /> and remove them if you're find same tag starts with </. Exclude tags that may not to have close tag, generate close tags for all tags that still in collection and place them at the end of yours Rich TextEditor layout. It may not work in some cases or looks clumsy but that first that comes in mind and it may help to solve the problem
To start off, I don't even know if I used the proper terminology. What I'm talking about is let's say I have a program that displays the value of a string and it also allows me to edit the value. What I want to do is when I begin to edit the value, the original value will be placed in my input so it'll be as if I manually typed in the original value and am able to use backspace and stuff.
It's like I just changed the value to a very long sentence and I realized I misspelled one word so when I edit the value the original pops up so I can use the arrow keys to move to the word and fix it, instead of having to retype the entire sentence.
I think you want to use a C# wrapper for the curses terminal control library.
I need to create a usercontrol "Console".
I was faced with such problems:
If I use a TextBox, how do I prevent removal of an already recruited command?
If I use a ListBox/ListView, how do I select all the text?
Please tell me what to do from the Console.
The console should be able to complete the command (by pressing Tab), allow selection of text, and prevent the entry of already established commands.
Here is a start:
http://ansiconsole.codeplex.com
I used a bitmap, and render text to it. This way I have complete control over the input and output.
If you need some "simple" console application: insert commands, I presume in some DSL language, view result of execution, and other stuff, you can try to programm on RichTextBox base, which can give also some styling to content.
Reuse some already ready (complicated) editors, like for example:
Scintilla
And work to limit possibilities of that kind of component to fit your needs.
Regards.
You could consider deriving from the RichTextBox control, as Tigran suggested.
Depending on what you want the user to be able to do, you will have to put some logic in there that restricts what they can and cannot select. (For example, if you don't want them selecting previous commands). You can obtain the text that they've selected via the SelectedText property. And then put in your custom logic, for example, Ctrl+C will copy the text into a variable.
You may consider having a MaximumSize property so that old commands will be erased after the console becomes so large.
Winforms already has a type of Autocomplete that you could use, or simply keep a list of keywords and when the user presses TAB, fill in the first word in your list that starts with what they've already typed.
To obtain the command itself, and not any of the previous text that was entered, you will probably want to take everything from the LAST newline to the end.
The code may look something like this:
String allText = this.richTextBox1.Text; // All the text from the rich text box
Int32 lastIndex = allText.LastIndexOf("\n"); // Find the position of the last newline
String command = allText.Substring(lastIndex + 1); // Substring starting at the character after the last newline
And of course when the user presses RETURN, the command will be sent to your code and executed.