string-formatting

how to edit a WPF textbox which uses multibinding and string.format?

喜你入骨 提交于 2019-12-04 11:46:35
I have the following code. This displays data in following format H:M:S. I would like to edit these values...and wanted to be notified in viewmodel. How do I achieve that ? Any help would be appreciated. Thanks <TextBox DataContext="{Binding UpdateSourceTrigger=PropertyChanged}" > <TextBox.Text> <MultiBinding StringFormat=" {0}:{1}:{2}"> <Binding Path="ValueH" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged" /> <Binding Path="ValueM" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged" /> <Binding Path="ValueS" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged" /> </MultiBinding> </TextBox

J2ME - number format

╄→尐↘猪︶ㄣ 提交于 2019-12-04 11:41:38
I need to format decimal numbers with patterns in J2ME just like java DecimalFormat . I see an option to port Format / NumberFormat / DecimalFormat . Can you suggest ready to use implementation or library? Thanks! So, I've manage to port desktop java implementation: bbnumberformat : String[] patterns = new String[] { "#,#00.00#", "0.0;(0.0)", "0.###E0" }; DecimalFormat format = (DecimalFormat) DecimalFormat .getNumberInstance(); double value = -12.321; for (int i = 0; i < patterns.length; i++) { String pattern = patterns[i]; format.applyPattern(pattern); String text = "Pattern: " + pattern + "

AngularJS - How to apply currency filter on textbox as I type?

£可爱£侵袭症+ 提交于 2019-12-04 10:49:57
My project has a requirement to show amount field in currency format. I can achieve this onblur event, but let me know if this can be achieved using filters or some other AngularJS technique. I have the following textbox: <input type="text" class="form-control" id="MyAmount" name="MyAmount" ng-model="MyAmount" /> I want to convert the value inside this text box to follow currency format. So, if I type 200000, it should make is $200,000.00 as soon as I type or while I am typing. I used the following technique and applied a filter, <input type="text" class="form-control" id="MyAmount" name=

Named parameter string formatting in C++

喜你入骨 提交于 2019-12-04 10:12:56
问题 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

Python-equivalent string formatting with dictionary in Perl with hashes

懵懂的女人 提交于 2019-12-04 10:05:57
I love the way Python can format a string with a dictionary: print "%(key1)s and %(key2)s" % aDictObj I want to achieve the same thing in Perl with hashes. Is there any snippet or small library to do so? EDIT: Thanks for trying this answer. As for me, I came out with a short piece of code: sub dict_replace { my ($tempStr, $tempHash) = @_; my $key; foreach $key (sort keys %$tempHash) { my $tmpTmp = $tempHash->{$key}; $tempStr =~ s/%\($key\)s/$tmpTmp/g; } return $tempStr; } It just works. This is not as feature-complete as Python string-formatting with a dictionary but I'd like to improve on

ASP.NET WebAPI: How to control string content returned to client?

纵然是瞬间 提交于 2019-12-04 09:05:01
问题 In WebAPI, say I return a string wrapped in an HTTP response: return Request.CreateResponse(HttpStatusCode.BadRequest, "Line1 \r\n Line2"); When invoking this action from jQuery, the response text is treated before it is returned. So in the xhr, I get something like this: function success(xhr) { alert(xhr.responseText); // alerts ""Line1 \\r\\n Line2"" } In other words, the string gets wrapped in double quotes, and special characters get escaped so that they appear in the output (actual alert

Join list of string to comma separated and enclosed in single quotes

微笑、不失礼 提交于 2019-12-04 08:50:17
问题 List<string> test = new List<string>(); test.Add("test's"); test.Add("test"); test.Add("test's more"); string s = string.Format("'{0}'", string.Join("','", test)); now the s is 'test's','test','test's more' but I need to replace the inner quotes with 2 single quotes like this: 'test''s','test','test''s more' update: I got it to work as below, but I would prefer a cleaner way if possible. string s = string.Format("`{0}`", string.Join("`,`", test)).Replace("'", "''").Replace("`", "'"); 回答1:

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

被刻印的时光 ゝ 提交于 2019-12-04 08:47:48
问题 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

StringFormat in XAML, WPF : Currency Formatting

邮差的信 提交于 2019-12-04 07:58:51
How can i obtain currency formatting according to my country i.e indian rupee, INR or Rs ?? Please tell me the way to achieve this ?? Right now when i use StringFormat="{}{0:C}" , "$" is being used I have gone through this link and i am able to achieve the desired result but i am worried about using this in my project. Is this code safe ?? What does this line mean in the above link "when you test functionality related to settings change it’s important you start the program directly from a folder window, if you run it from within Visual Studio or any other program you may get incorrect results.

How to format a QString?

这一生的挚爱 提交于 2019-12-04 07:48:59
问题 I'd like to format a string for Qt label, I'm programming in C++ on Qt. In ObjC I would write something like: NSString *format=[NSString stringWithFormat: ... ]; How to do something like that in Qt? 回答1: You can use QString.arg like this QString my_formatted_string = QString("%1/%2-%3.txt").arg("~", "Tom", "Jane"); // You get "~/Tom-Jane.txt" This method is preferred over sprintf because: Changing the position of the string without having to change the ordering of substitution, e.g. // To get