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"
Related
I have a TextBox in a WPF project that contains a complex Regex pattern like this:
<TextBox x:Name="tbPattern" TextWrapping="Wrap" VerticalAlignment="Stretch" FontFamily="Consolas"
Text="^(?type>([A-Z]|[0-9])+)_(?Y>\d{4})(?M>0[1-9]|1[0-2])(?d>0[1-9]|[1-2][0-9]|3[0-1])_(?H>([0-1][0-9]|2[0-3]))(?m>([0-5][0-9]))(?s>([0-5][0-9]))(~(?n>[1-9][0-9]*))?\.(?ext>([A-Z|a-z|0-9]+))$"
/>
(Yes, the regex syntax is invalid, but it's only for testing purpose...)
Because the pattern is not expected to contain many spaces, I would like to wrap the text box text always at the end of the line, ignoring space characters before, like command inputs use to do it (simply open cmd and insert the pattern. In each line, all characters will range up to the last column).
So I tested available TextWrapping properties but could not found the right one. NoWrap produces some very chaotic display, while simple Wrap option distributes the pattern over non-equally long lines. This is also done by WrapWithOverflow.
How can I use a wrapping algorithm in cmd style that does not search for spaces to earlier breaking line? Thanks in advance.
You can replace space to non-breaking space.
Replace(" ", "\u00a0")
And you can bind replaced value via a property for preserve the original text. Or you can also use a converter.
I'm making a detail page about certain items.
This detail page can contain large blocks of text, and the customer would like to only show the first 100 letters and then put a " ... more " at the end.
When the user clicks this " ... more " the rest of the text can be shown.
Biggest problem: the text is currently is a CMS and has large varieties. Some is pure text, some have html elements in them ...
I tried to cut off the text and put them in spans. Then i could show/hide these spans as i please. The issue here is that there can be a starting element of a certain tag in the first span and the closing element can be in the second span. This causes the DOM hierarchyto be faulty and the result is never pretty.
Does anyone know a ( other ) way to achieve this or a library i can use ?
To be able to extract "readable" characters you need to get the content into a plain text format (get rid of the mark-up).
Since the content is stored in a cms it is likely that the content is structured to be well formed - thus xhtml.
If that is the case you can treat the content as XML. Get the root node and get the innertext property there-of. Then you will have plain text - no tags - and can easily cut it after the first 100 characters or whatever the requirement is.
Hopefully the content doesn't contain js/css!
Edit:
It seems that the markup must be retained.
Try the following xsl to transform and truncate the content:
https://gist.github.com/allen/65817
I have a substring what contains HTML tag and I need to shorten it but display it with the same formatting as it appears on the string.
It doesn't have to be exactly X characters long, but it should be short enough to be displayed inside a panel with a certain width and height?
Is there any way I can achieve this using c#?
What about using CSS? I.e. displaying the panel with a fixed height regardless of its content?
Thanks..
Example: I have the following panel containing a label that contains text with html tags:
I need to remove the scroll bar without making the panel longer but keeping this height & this width..
If you have following html code:
<div class="div1"> Some Really Bold String </div>
You can provide css to hide the scroll bars,
.div { overflow:hidden; height:200px; width:200px;}
height and width values are just for example purpose.
overflow:hidden does not let the content of the div to expand out side the div.
you will find more information on overflow here.
You could use a regex to find the contents of the specific tag. Use a .substring to shorten the result afterwards.
A example could be:
<h1>head</h1>
<p>contents</p>
Regex could be:
<p\b[^>]*>(.*?)</p>
Result would be:
<p>contents</p>
Now just exclude the start and end tag. as its a fixed length.
I found more interesting reading about changing the content between HTML tags. Take a read here (regex ftw!):
http://www.thatsquality.com/articles/how-to-match-and-replace-content-between-two-html-tags-using-regular-expressions
Another solution that might not drive you as crazy if you want to solve it in c#:
HTML Agility Pack
Take a look at the examples part of the site. Great little tool!
I want to be able to read text from a Silverlight TextBlock (TextBlock Control) (Silverlight & C#) and check what formatting (as in: bold, italic, font size, etc...) has been applied to it, so I can store it in an XML file.
Is it possible to find out what formatting has been applied to a piece of text with C# and Silverlight so it can be stored and re-used later? The text would be contained within a textbox or textblock control.
Storage used can be XML but I've just found out Silverlight doesn't support XSL, so just XML.
Regards,
T
Just make sure you give your control a name.
<Textblock x:Name="myTextBlock" />
In your code behind you can then access the TextBlock but calling it's name (myTextBlock).
Here you can add logic like:
if (myTextBlock.FontWeight == "Bold")
{
//Do Something
}
From reading your needs you'll most likely be passing the object to a function and creating your xml file from there. Good luck.
By formatting you mean a phone number or date format?
If yes. Use regular expressions.
Take a look at the System.Text.RegularExpressions namespace. Everything there should help you.
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();