text-formatting

WPF TextBlock formatting bold from string property

让人想犯罪 __ 提交于 2021-01-28 11:44:22
问题 I have binded TextBlock text to a string property. Xaml look like: <TextBlock Text="{Binding Message}" TextWrapping="Wrap"/> Property on the ModelView class look like: private string message; public string Message { get { return message; } set { message = value; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Message))); } } I want to be able to use Textblock formatting abilities such as bold. for example: Message = "Some string with <Bold>bold</Bold> words"; On run time

Prevent input type=“number” from getting more than one dot in its value and limit decimals numbers

為{幸葍}努か 提交于 2020-06-07 07:38:45
问题 Inbefore: I know this question has been asked more than once on this forum. I know I could post my answer on these other posts. My issue is that the users who asked those questions did it 3 - 4 years ago, and looking at their autors profile, they do not seem very active and I beleive the questions would never be marked as solved. So I've been looking around every where to find help on doing exactly that, with no simple solutions allowing to limit the user from typing more than one dot in an

Use a custom thousand separator in C#

与世无争的帅哥 提交于 2020-01-08 16:55:33
问题 I'm trying not to use the ',' char as a thousand separator when displaying a string, but to use a space instead. I guess I need to define a custom culture, but I don't seem to get it right. Any pointers? eg: display 1000000 as 1 000 000 instead of 1,000,000 (no, String.Replace() is not the solution I'd like to use :P) 回答1: I suggest you find a NumberFormatInfo which most closely matches what you want (i.e. it's right apart from the thousands separator), call Clone() on it and then set the

Use a custom thousand separator in C#

若如初见. 提交于 2020-01-08 16:55:13
问题 I'm trying not to use the ',' char as a thousand separator when displaying a string, but to use a space instead. I guess I need to define a custom culture, but I don't seem to get it right. Any pointers? eg: display 1000000 as 1 000 000 instead of 1,000,000 (no, String.Replace() is not the solution I'd like to use :P) 回答1: I suggest you find a NumberFormatInfo which most closely matches what you want (i.e. it's right apart from the thousands separator), call Clone() on it and then set the

Java change system new-line character

有些话、适合烂在心里 提交于 2020-01-03 13:40:07
问题 On Windows, using System.out.println() prints out \n\r while on a Unix system you would get \n . Is there any way to tell java what new-line characters you want to use? 回答1: Yes, there is a way and I've just tried it. There is a system property line.separator . You can set it using System.setProperty("line.separator", whatever) To be sure that it indeed causes JVM to use other separator I implemented the following exercise: PrintWriter writer = new PrintWriter(new FileWriter("c:/temp/mytest

Nice bit of code to format an xml string

假装没事ソ 提交于 2019-12-31 19:59:53
问题 Anyone got a ready made function that will take an XML string and return a correctly indented string? eg <XML><TAG1>A</TAG1><TAG2><Tag3></Tag3></TAG2></XML> and will return nicely formatted String in return after inserting linebreaks and tabs or spaces? 回答1: The RTL has FormatXMLData in XMLDoc.pas that accepts and returns strings. 回答2: Using OmniXML: program TestIndentXML; {$APPTYPE CONSOLE} uses SysUtils, OmniXML, OmniXMLUtils; function IndentXML(const xml: string): string; var xmlDoc:

Aligning based on the width of letters with sprintf

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-25 14:11:33
问题 I'm attempting to align a text-based list of items for an e-mail. Basically the problem I have is that it only works with fixed-width (monospaced) fonts - I'd like a script that somehow can align it based on the width of each letter in a standard Arialish font. function sprintf_nbsp() { $args = func_get_args(); return str_replace(' ', ' ', vsprintf(array_shift($args), array_values($args))); } $format = '%-6s%-\'.35.35s...%\'.10s<br>'; $str = sprintf_nbsp($format, '1', 'A list of items - this

Format number between markers as subscript

笑着哭i 提交于 2019-12-25 03:52:36
问题 I would like to find a number between two hashtags, delete the hashtags and format the number that was between the hashtags as subscript. Example: The text ##12## should be converted to 12 . Here is my code so far: Public Sub SubscriptText() With Selection.Find .ClearFormatting .Text = "##" .Replacement.ClearFormatting .Replacement.Text = "##" .Execute Replace:=wdReplaceAll, Forward:=True, Wrap:=wdFindContinue End With End Sub This removes the ## , but how do I format the number as subscript?

Have half a UILabel text bold and half not?

浪尽此生 提交于 2019-12-24 11:40:18
问题 I want half of my UILabel 's text to be bold and half to not be bold. How can I do this? 回答1: NSAttributedString allows for specification of formatting within a string, but sadly, UIKit does not yet do anything with this. However, there are a few open-source implementations that do. Check out OHAttributedLabel. 回答2: You can't do this easily unless you subclass UILabel and mess with the subviews. Better to use two UILabels instead. Found another thread about it here. 回答3: UILabel has

Detect when caret position changes in RichTextBox

安稳与你 提交于 2019-12-24 11:35:01
问题 I am trying to implement very simple text formatting functionality for a RichTextBox in WPF. This just consists of a few bold, italic, etc ToggleButtons just above the RichTextBox. See image below, but ignore the top TextBox - the RichTextBox is the bigger one at the bottom. Toggling formatting for either a selection or at the caret position (for text that will be typed in) is not a problem, as I'm doing this: private void BoldButton_Checked(object sender, RoutedEventArgs e) { this