string-formatting

Problem with UpdateSourceTrigger=PropertyChanged and StringFormat in WPF

℡╲_俬逩灬. 提交于 2019-12-03 08:59:45
I have a text box in my application which is data bound to a decimal field in my class and the binding mode is two way. I am using StringFormat={0:c} for currency formatting. This works fine as long as I don't touch 'UpdateSourceTrigger'. If I set UpdateSourceTrigger=PropertyChanged , It stops formatting the text that I am entering. here is my code example Employee.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ComponentModel; namespace Converter { public class Employee : INotifyPropertyChanged { int _employeeNumber; string _firstName;

advanced string formatting vs template strings

耗尽温柔 提交于 2019-12-03 08:08:43
问题 I was wondering if there is a advantage of using template strings instead of the new advanced string formatting? 回答1: Templates are meant to be simpler than the the usual string formatting, at the cost of expressiveness. The rationale of PEP 292 compares templates to Python's % -style string formatting: Python currently supports a string substitution syntax based on C's printf() '%' formatting character. While quite rich, %-formatting codes are also error prone, even for experienced Python

Named parameter string formatting in C++

偶尔善良 提交于 2019-12-03 06:03:46
I'm wondering if there is a library like Boost Format, but which supports named parameters rather than positional ones. This is a common idiom in e.g. Python, where you have a context to format strings with that may or may not use all available arguments, e.g. mouse_state = {} mouse_state['button'] = 0 mouse_state['x'] = 50 mouse_state['y'] = 30 #... "You clicked %(button)s at %(x)d,%(y)d." % mouse_state "Targeting %(x)d, %(y)d." % mouse_state Are there any libraries that offer the functionality of those last two lines? I would expect it to offer a API something like: PrintFMap(string format,

casting NSInteger into NSString

非 Y 不嫁゛ 提交于 2019-12-03 05:41:23
I'm trying to make one string out of several different parts. This below is what i have right now. I don't get any errors in my code but as soon as i run this and do the event that triggers it i get EXC_BAD_ACCESS . Is there another way of casting this NSInteger into a NSString ? NSString *part1, *part2, *tempString; NSInteger num1; NSInteger num2; part1=@"some"; part2=@"text"; tempString = [NSString stringWithFormat:@"%@%@%@%@", part1, (NSString *)num1, part2, (NSString *)num2]; A string and an integer are fundamentally different data types, and casting in Objective-C won't do a conversion

Format a Social Security Number (SSN) as XXX-XX-XXXX from XXXXXXXXX

做~自己de王妃 提交于 2019-12-03 05:34:49
I am getting a social security number (SSN) from a data warehouse. While posting it to a CRM I want it to be formatted like XXX-XX-XXXX instead of XXXXXXXXX . It's like converting a simple string with dashes at positions 4 and 7 . I am pretty new to C#, so what is the best way to do this? Check out the String.Insert method. string formattedSSN = unformattedSSN.Insert(5, "-").Insert(3, "-"); For a simple, short, and self commenting solution, try: String.Format("{0:000-00-0000}", 123456789) 123456789 representing your SSN variable. string ssn = "123456789"; string formattedSSN = string.Join("-",

Decimal stores precision from parsed string in C#? What are the implications?

一笑奈何 提交于 2019-12-03 05:20:46
During a conversation on IRC, someone pointed out the following: decimal.Parse("1.0000").ToString() // 1.0000 decimal.Parse("1.00").ToString() // 1.00 How/why does the decimal type retain precision (or, rather, significant figures) like this? I was under the impression that the two values are equal, not distinct. This also raises further questions: How is the number of significant figures decided during mathematical operations? Does the number of significant figures get retained during serialization? Does the current culture affect the way this is handled? How is the number of significant

Should we store format strings in resources?

无人久伴 提交于 2019-12-03 04:34:19
For the project that I'm currently on, I have to deliver specially formatted strings to a 3rd party service for processing. And so I'm building up the strings like so: string someString = string.Format("{0}{1}{2}: Some message. Some percentage: {3}%", token1, token2, token3, number); Rather then hardcode the string, I was thinking of moving it into the project resources: string someString = string.Format(Properties.Resources.SomeString, token1, token2, token3, number); The second option is in my opinion, not as readable as the first one i.e. the person reading the code would have to pull up

Python 3: using %s and .format()

家住魔仙堡 提交于 2019-12-03 04:32:44
I have finally switched from % to the .format() string formatting operator in my 2.x code in order to make it easier to migrate to 3.x in future. It was a bit surprising to find out that not only the % -style formatting remains in Py3, but it is widely used in the standard library code. It seems logical, because writing '(%s)' % variable is a bit shorter and maybe easier to comprehend than '({})'.format(variable) . But I'm still in doubt. Is it proper (pythonic?) to use both approaches in the code? Thank you. Vlad Python 3.2 documentation said that, % will eventually go away. http://docs

Format BigDecimal without scientific notation with full precision

被刻印的时光 ゝ 提交于 2019-12-03 04:21:51
I'd like to convert a BigDecimal to String for printing purposes but print out all digits without scientific notation. For example: BigDecimal d = BigDecimal.valueOf(12334535345456700.12345634534534578901); String out = d.toString(); // Or perform any formatting that needs to be done System.out.println(out); I'd like to get 12334535345456700.12345634534534578901 printed. Right now I get: 1.23345353454567E+16 . To preserve the precision for a BigDecimal you need to pass the value in as a String BigDecimal d = new BigDecimal("12334535345456700.12345634534534578901"); System.out.println(d

C# - Insert a variable number of spaces into a string? (Formatting an output file)

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-03 04:10:13
Alrighty, I'm taking data from a list that I populate a DataGridView with and am exporting it to a text file. I've already done the function to export it to a CSV, and would like to do a plain text version as well. Because the Titles and other elements are variable in length, when the file is saved and then opened in Notepad it looks like a mess because nothing lines up. I'd like to have the output look like this: Sample Title One Element One Whatever Else Sample Title 2 Element 2 Whatever Else S. T. 3 E3 Whatever Else I figure that I can loop through each of the elements in order to get the