string-formatting

% operator in python over string

What does the following Python statement mean? send_data="" str_len = "%#04d" % (len(send_data)/2) ...

std::string and format string

I found the below code through Google. It almost does what I want it to do, except it doesn't provide a way to indicate the precision like '%.*f' does in C-type format strings. Also, it doesn't provide anything further than 5 decimal places. Am I going to have to stick with C strings and snprintf? #include <string> #include <sstream> #i...

convert .net format string to java format string

I am looking at the format specifiers of C# and the patterns for formatting numeric strings in Java. I am wondering if anyone has any pointers as to translating from one form to another? ...

Add comma thousand seperator to decimal (.net)

I have a decimal number, say 1234.500. I want to get it to display 1,234.4 Im currently converting it to a double to remove the trailing '0's. string.Format("{0:0,0}",1234.500) removes the decimal place, and other formatting options seem to use two decimal places regardless. Can anyone offer insight? ...

What is the best data type to use in order to store numbers with leading zeroes?

In Access 2003 I need to display numbers like this while keeping the leading zeroes: 080000 090000 070000 What is the best data type to use for this? ...

Pythonic way to print a table

I'm using this simple function: def print_players(players): tot = 1 for p in players: print '%2d: %15s \t (%d|%d) \t was: %s' % (tot, p['nick'], p['x'], p['y'], p['oldnick']) tot += 1 and I'm supposing nicks are no longer than 15 characters. I'd like to keep each "column" aligned, is there a some syntactic suga...

Is there a way to store and manipulate a span of time that takes month lengths, leap years, etc. into account?

I was just about to write this myself, but I know this has to exist and I'm just managing to avoid all the Google keywords that would lead me right to it. I would be looking for something like DDDMMMYYY where D, M, Y are the number of days, months, and years. So 00103000 would indicate a span of three months and one day, or 000000001 wo...

Is there a PHP function to format a currency amount in accounting format?

I'm currently writing a report in PHP that occasionally has to display negative currency amounts. Said currency amounts are stored in the database like "-44.00". Ideally this number would be output as "($44.00)" on the report. I know I can write some semi-complicated function to detect whether the number is negative and manually insert ...

Python string formatting special characters.

How do you make the following code work? example = "%%(test)%" % {'test':'name',} print example Where the desired output is "%name%" Thanks ...

python string replacement with % character/**kwargs weirdness

Following code: def __init__(self, url, **kwargs): for key in kwargs.keys(): url = url.replace('%%s%' % key, str(kwargs[key])) Throws the following exception: File "/home/wells/py-mlb/lib/fetcher.py", line 25, in __init__ url = url.replace('%%s%' % key, str(kwargs[key])) ValueError: incomplete format The string has a forma...

Python, sending command to GPIB instrument

I need to send a command to a GIPB instrument and I can do it like this: power.write("volt 0.01"). This command sets the output of my power source to 0.01V, however, I'm trying to take an I-V curve and want to set the source to different values and take a measurement at each value. I basically need some sort of loop to do this for me, I ...

String.Format an integer to use 1000's separator without leading 0 for small integers

Silly question, I want to format an integer so that it appears with the 1000's separator (,), but also without decimal places and without a leading 0. My attempts so far have been: String.Format("{0} {1}", 5, 5000); // 5 5000 String.Format("{0:n} {1:n}", 5, 5000); // 5.00 5,000.00 String.Format("{0:0,0} {1:0,0}", 5, 5...

How do I use TeX/LaTeX formatting for custom data tips in MATLAB?

I'm trying to annotate a polar plot with data tips labelled with 'R:...,Theta:...' where theta is actually the Greek symbol, rather than the word spelled out. I'm familiar with string formatting using '\theta' resulting in the symbol, but it doesn't work in this case. Is there a way to apply the LaTeX interpreter to data tips? Here's wha...

Adding an extension method to the string class - C#

Not sure what I'm doing wrong here. The extension method is not recognized. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using StringExtensions; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { ...

how to store printf into a variable?

I want to store a formatted string using something similar to what printf does in C. char *tmp = (char *)sqlite3_column_text(selectstmt, 2); const char *sqlAnswers = printf("select key from answer WHERE key = %s LIMIT 5;", tmp); The following is an error obviously, I am sure alot of c programmers out there would give me a quick answer...

Easiest way to format a number with thousand separators to an NSString according to the Locale

I can't seem to find an easy way to do it. The exact thing I need is: [NSString stringWithFormat:@"%d doodads", n]; Where n is an int. So for 1234 I'd want this string (under my locale): @"1,234 doodads" Thanks. ...

Width and Precision using *

I'm learning Python from a book and came across this example: >>> '%f, %.2f, %.*f % (1/3.0, 1/3.0, 4, 1/3.0) # Result: '0.333333, 0.33, 0.3333' Don't quite understand what's happening here, especially the '4' in between. ...

Linq-to-Entities: Format Date in select query expression

I am trying to get a formatted date string directly from a LINQ-to-Entities query expression. nonBusinessDays = (from ac in db.AdminCalendar where ac.DateTimeValue >= calendarStartDate && ac.DateTimeValue <= calendarEndDate && ac.IsBusinessDay == false select ac.MonthValue + "/" + ac.DayOfMonth + "/...

Lua string.format options

This may seem like a stupid question, but what are the symbols used for string replacement in string.format? can someone point me to a simple example of how to use it? ...

VBScript: What is the simplest way to format a string?

I have the following format: Value1 is {0} and Value2 is {1}. I need to replace the numbers in the brackets with strings. This is easily done in most languages using string.Format or something along those lines. How can I do this using only vbscript? I've tried: Replace (strFormat, "{0}", value1) Replace (strFormat, "{1}", value...