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.
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"
How i can read the content of a Windows 8 WinRT TextBox line for line in C#? I found nowhere a method for this? It's not working like in .Net
var lines = textboxName.Text.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
would give you lines from a textbox explicitly split according to the content of the box. (Removing empty entries accounts for the fact that Environment.NewLine is actually two characters long.)
If you want to get a string split by the UI in a multiline textbox (i.e. where wrapping occurs) you'll have to go into more detail with measuring strings, etc, but I wouldn't recommend it unless you absolutely have to have the strings as laid out by the UI
So i'm looking to scrape rapidshare.com links from websites. I have the following regular expressions to find links:
<a href=\"(http://rapidshare.com/files/(\\d+)/(.+)\\.(\\w{3,4}))\"
http://rapidshare.com/files/(\\d+)/(.+)\\.(\\w{3,4})
How can I write a regex that will exclude text that is embedded in a tag. and only capture the text in >here
I also have to bare in mind that not all links are embedded in href tags. Some are just displayed in plain text.
Basically is there a wway to exclude patterns in regex ?
Thanks.
To capture the inner text of an anchor tag, while ignoring all attribute text of the tag, you'd use the pattern:
<a href="http://rapidshare.com/files/(\d+)/(.+)\.(\w{3,4})[^>]*>(.*?)</a>
The [^>]* part matches everything else in your tag up until the end of the start tag.
The (.*?) performs a non-greedy capture of the inner text.
If you want to capture anchor tag links and non-anchor tag links, then those are really two separate problems. There's probably a regex for it, but it would be terribly complicated. You're better off simply looking for non-anchor-tag links separately with the simple regex:
[^'"]http://rapidshare.com/files/(\d+)/(.+)\.(\w{3,4})
How about like this, last part will try to match any thing except ' " >
http://rapidshare.com/files/(\d+)/([^'"> ]+)
How about something like:
/http:\/\/rapidshare.com\/files\/\d+\/[^<&\s]+\.\w{3,4}/
I got rid of the capturing groups, because I think you only had them in there because you thought you might need them to make sure the different groupings worked and you can add them back in if you really want them parsed out.
You can expand upon the [^<&"\s] as it only is excluding white spaces, the < character which could be the start of the tag, the & which would include things like and other HTML entities or the " which would be the end of the href=. but you could exclude any non-valid URI character if you wanted. This should cover your inline text as well as those embedded as href.
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();