string-formatting

Android: Format string to html - add new lines <br/> [duplicate]

浪子不回头ぞ 提交于 2020-01-02 22:17:25
问题 This question already has answers here : replace \n and \r\n with <br /> in java (7 answers) Closed 5 years ago . I need to format text coming from user to HTML, but the input is multiple line and I have to replace all "enters" from that string to HTML <br /> tags. String message = messageEditText.getText().toString(); This is the message I want to format. How can I format the string accordingly? 回答1: try message = message.replace ("\\r\\n", "<br>").replace ("\\n", "<br>"); 回答2: You can use

Custom date format for textbox

主宰稳场 提交于 2020-01-02 10:33:12
问题 Related: Binding 3 textboxes together; same DateTime different format I have three textboxes , all are supposed to be bound together with the same date. Two of them have normal string formats. The third one has a specific format of yyyy,jjj/HHmmss . I can't figure out how to bind this textbox to the custom format I have, and make it so if I change any of the date values in it, the other textboxes will update and vice versa. private DateTime _dateInViewModel; public DateTime DateInViewModel {

Technique on how to format/color NSTextView's string

依然范特西╮ 提交于 2020-01-02 02:33:08
问题 I'm looking for a reliable technique to do simple string formatting(bold, italic,...) in a NSTextView. The text parsing is almost done with regex, but now I need to apply font trait and also change the size. Some code snippets on how I make a text bold [[textView textStorage] beginEditing]; [[textView textStorage] applyFontTraits:NSFontBoldTrait range:range]; [[textView textStorage] endEditing]; This and also the size changes with [[textView textStorage] beginEditing]; NSFont* font = [

How can I format a number as xxx-xx-xxxx?

你说的曾经没有我的故事 提交于 2020-01-01 09:04:19
问题 I am querying social security number data from a stored procedure and I would like to format it as a social security number in my stored procedure. How can I format xxxxxxxxx like xxx-xx-xxxx in Oracle? 回答1: SSN formatting with TO_CHAR SELECT TO_CHAR(012345678, '000g00g0000','nls_numeric_characters=.-') ssn from dual; SSN ----------- 012-34-5678 update: thanks to Gary for pointing out that the '0' format character should be used rather than the '9' to preserve leading zeroes. 回答2: you could

String.Format - How can I format to x digits (regardless of decimal place)?

孤者浪人 提交于 2020-01-01 08:15:07
问题 I need to format a floating point number to x characters (6 in my case including the decimal point). My output also needs to include the sign of the number So given the inputs, here are the expected outputs 1.23456 => +1.2345 -12.34567 => -12.345 -0.123456 => -0.1234 1234.567 => +1234.5 Please assume there is always a decimal place before the last character. I.e. there will be no 12345.6 number input - the input will always be less than or equal to 9999.9 . I'm thinking this has to be done

String.Format - How can I format to x digits (regardless of decimal place)?

百般思念 提交于 2020-01-01 08:15:04
问题 I need to format a floating point number to x characters (6 in my case including the decimal point). My output also needs to include the sign of the number So given the inputs, here are the expected outputs 1.23456 => +1.2345 -12.34567 => -12.345 -0.123456 => -0.1234 1234.567 => +1234.5 Please assume there is always a decimal place before the last character. I.e. there will be no 12345.6 number input - the input will always be less than or equal to 9999.9 . I'm thinking this has to be done

Format string template with variables in Javascript

自闭症网瘾萝莉.ら 提交于 2020-01-01 08:02:50
问题 I want to use a statically defined template for URL building. I'm trying to use ES6 string interpolation feature for this var template = "http://example.com/?name=${name}&age=${age}"; var name = "John"; var age = "30"; var url = `${template}`; Expected result: http://example.com/?name=John&age=23 Actual result: http://example.com/?name=${name}&age=${age} In case this can't be done with string interpolation is there any better method than String.prototype.replace like var url = template

Format string template with variables in Javascript

試著忘記壹切 提交于 2020-01-01 08:02:12
问题 I want to use a statically defined template for URL building. I'm trying to use ES6 string interpolation feature for this var template = "http://example.com/?name=${name}&age=${age}"; var name = "John"; var age = "30"; var url = `${template}`; Expected result: http://example.com/?name=John&age=23 Actual result: http://example.com/?name=${name}&age=${age} In case this can't be done with string interpolation is there any better method than String.prototype.replace like var url = template

Advanced formatting rules for StringBuilder.AppendFormat

こ雲淡風輕ζ 提交于 2020-01-01 05:54:30
问题 I've seen on this site a StringBuilder code sample illustrating AppendFormat usage: using System; using System.Text; class Program { static int[] _v = new int[] { 1, 4, 6 }; static void Main() { StringBuilder b = new StringBuilder(); foreach (int v in _v) { b.AppendFormat("int: {0:0.0}{1}", v, Environment.NewLine); } Console.WriteLine(b.ToString()); } } === Output of the program === int: 1.0 int: 4.0 int: 6.0 Where can I find documentation on those advanced rules for string formatting? 回答1:

String Format Integer With Commas, No Decimal Places and Nothing for 0 Values

ぐ巨炮叔叔 提交于 2020-01-01 05:12:47
问题 Okay before I get right into my question does anyone know if there is a tool for building string formats? What I'm thinking is something like a pretty simple user interface where you choose whether you want to display commas, zero values, dollar signs etc and then it spits out the stringformat for you. If there is one I'd love to know about it. If there's not it's the sort of thing people like me would love! My question is. What is the string format for displaying an integer with comma