string-formatting

Customize display of an enumeration class

旧城冷巷雨未停 提交于 2019-12-06 05:22:21
I'd like to customize the display of an enumeration class using matlab.mixin.CustomDisplay . If I have a regular (non-enumeration) class such as the following: classdef test < handle & matlab.mixin.CustomDisplay properties value end methods function obj = test(value) obj.value = value; end end methods (Access = protected) function displayScalarObject(obj) disp(['hello ', num2str(obj.value)]) end end end then everything works fine - for example, >> a = test(1) a = hello 1 But if I have an enumeration class such as the following (note the addition of the enumeration block): classdef test <

Is there any way to make visual C++ (9.0) generate warnings about printf format strings not matching type of printf's args?

爱⌒轻易说出口 提交于 2019-12-06 04:58:07
问题 Gcc nicely provides -Wformat to help with finding printf related bugs. Is there any way to get the same behavior in MSVC? Specifically I'd like the compiler to do some level of type checking on the arguments. I explicitely don't want to use C++'s iostream library for various reasons. (and I also don't want to use boost format). To quote the source above, -WFormat basically provides the following capabilities Check calls to printf and scanf, etc., to make sure that the arguments supplied have

Python-equivalent string formatting with dictionary in Perl with hashes

对着背影说爱祢 提交于 2019-12-06 04:38:55
问题 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

Matplotlib text alignment

僤鯓⒐⒋嵵緔 提交于 2019-12-06 03:37:28
问题 Is there a way to get the result shown in the third axes with just a single ax.text() command? Using expandtabs almost get me there, but the text never aligns properly. Using two plotting commands doesn't seem like a good practice to me, and you always need to guess the distance between both, which might take some iterations. fig, axs = plt.subplots(1,3, figsize=(12,4), subplot_kw={'aspect': 1, 'xticks': [], 'yticks':[]}) fig.subplots_adjust(wspace=0.05) values = {'a': 1.35, 'b': 25.1, 'c': 5

Java Date Parsing Timezone causing parse error

拈花ヽ惹草 提交于 2019-12-06 02:05:32
I'm receiving a ParseException with the following code and I can't seem to fix it: String date = "Tue Mar 13 2012 10:48:05 GMT-0400"; SimpleDateFormat format = new SimpleDateFormat("EEE MMM dd yyyy HH:mm:ss zzzX"); //Tried zzzZ at the end as well System.out.println(format.parse(date)); If I take out the -0400 and the X (or Z) at the end of the SimpleDateFormat things work fine, but once it's in the code, it simply doesn't work. What symbol should I be using instead? I'm using Java 7. Here is the parse error I receive: java.text.ParseException: Unparseable date: "Tue Mar 13 2012 10:48:05 GMT

Using Html.fromHtml to set custom Typeface

不想你离开。 提交于 2019-12-06 00:49:59
问题 I found this list of HTML-Tags that are (supposedly) supported for HTML.fromHtml to create a Spanned-Text: http://commonsware.com/blog/Android/2010/05/26/html-tags-supported-by-textview.html Now is there ANY way to set a custom Typeface with the Font-Tag? 回答1: Outdated. See other answers. No, there's no way to do so. You can take a look at the Html implementation. As you will see, the font tag supports size and color only. 回答2: Simply use a <font> tag with a face attribute. This has been

Is there a way to convert C-format strings for C# -format strings in C#/.NET 2.0?

寵の児 提交于 2019-12-05 23:41:28
So i would like to convert string like this: "Bloke %s drank %5.2f litres of booze and ate %d bananas" with a C# equivalent for .Format or .AppendFormat methods "Bloke {0} drank {1,5:f2} litres of booze and ate {2} bananas" sorry but i'm not sure if the C# version was correct but u got the idea. The solution does not have to be perfect but cover the basic case. Thanks & BR -Matti answered in my other question How to write C# regular expression pattern to match basic printf format-strings like "%5.2f"? You could probably just use StringBuilder.Replace() . StringBuilder cString = new

Python 3 - using tuples in str.format() [duplicate]

≯℡__Kan透↙ 提交于 2019-12-05 22:07:16
问题 This question already has answers here : What is the pythonic way to unpack tuples? [duplicate] (2 answers) Closed 5 years ago . I'm trying to use the str.format() method, and having some difficulties when my values are stored within a tuple. For example, if I do: s = "x{}y{}z{}" s.format(1,2,3) Then I get 'x1y2z3' - no problem. However, when I try: s = "x{}y{}z{}" tup = (1,2,3) s.format(tup) I get IndexError: tuple index out of range. So how can I 'convert' the tuple into separate variables?

WPF Image Source binding with StringFormat

▼魔方 西西 提交于 2019-12-05 21:30:30
I'm new to WPF and MVVM (started this week experimenting with it) and trying to bind image resources at runtime. The items I'm trying to display contain an enumerate property that indicates the type or state of the item: public class TraceEvent { /// <summary> /// Gets or sets the type of the event. /// </summary> /// <value>The type of the event.</value> public TraceEventType EventType { get; set; } } As far as I known the Source attribute of Image has a value converter that takes strings and returns Uri objects. <Image Source="{Binding Path=EventType, StringFormat={}/AssemblyName;component

Format Decimal 2 Places - no trailing zeroes

早过忘川 提交于 2019-12-05 21:26:59
The format: #,# formats my number but it rounds my decimals up. I need to keep my decimals. Is there a format for that? Thank you. #,#.### Ad as many # s as needed. To always show decimal places, use 0 s instead. You can truncate decimal places with (int)d If you need two decimals you can write (int)(100*d)/100.0 (int)(100*1.99999)/100.0 ==> 1.99 If you are trying to display it as a string, try this... yourVariable.ToString("{0:F2}"); This will format the string into a fixed point with two floating numbers. The Microsoft Custom Numeric Format Strings and Microsoft Standard Numeric Format