string-formatting

C#: Formating Price value string

in C#,I have a double variable price with value 10215.24. I want to show the price with comma after some digits.Can anyone help me to do this.My expected output is 10,215.24 ...

C++ Runtime string formatting

Usually I use streams for formatting stuff however in this case ?I don't know the format until runtime. I want to be able to take something like the following format string: Hello {0}! Your last login was on {1,date:dd/mm/yy}. ...and feed in the variables "Fire Lancer" and 1247859223, and end up with the following formatted string: Hell...

Formatting varchar data into a certain format.

I need to format data in a sql column that is currently entered like this: Z04000002003.7 The desired output of this would be: Z04/000/002/003.7 Every time a user enters data like this Z04000002003.7. The next time the user opens the record it would have automatically formatted it to display Z04/000/002/003.7. ...

Format currency without rounding

I have the need to format a decimal number as currency but I do not wish for any rounding to occur in the process. For example (example culture is en-US) Dim money = 1234.556789D money.ToString("C") ' Yields $1,234.56 (notice the rounding & truncating) money.ToString("C99") ' Yields $1,234.556789000000000000....0 -- close but not perf...

How might I format an alist in common lisp?

I'm beginning to write me some Common Lisp and am just getting the hang of consing things together and formatting them. Let's suppose I have an alist, like this: (defvar *map* '((0 . "zero") (1 . "one") (2 . "two"))) How do I format it like this? 0: zero 1: one 2: two I was thinking something like (format t "~{~{~a: ~a~}~%~}" *map...

FormatString question

Is there a built in FormatString or a way to use a custom FormatString to take: $150.00 $1,170.00 $12,170.00 $90.00 $38.00 $750.00 And format them like: $ 150.00 $ 1,170.00 $ 12,170.00 $ 90.00 $ 38.00 $ 750.00 without knowing the largest value? This is in a gridview boundcolumn I am currently in the codebehind on ...

Converting VB Format() to PHP

I'm trying to convert a encrypt/decrypt function from VB to PHP, but I'm having problems with this part: Format$(Hex$(AscSrc), ″@@″)` Is there a way to convert that to PHP? I couldn't find how to convert the @ symbol. ...

How do you format text/strings in VBA?

In the code below, I take some input parameters, either text or a cell, and combine them to form one string using the formatting I need. I need to make Task_Name bold, as well as text like "Lead :". I know you cannot make text in a variable bold, but how do I go about this? This cell I'm storing the value in is eventually used in a Wo...

looking for 'sed' like functionality in Excel

I use excel a lot to structure finite state machines. As such I often format cells so that I can cut and past entire sections into my C source directly. Currently I'm having to preprocess one of my code blocks so that I can replace "-" with "_" in my identifiers. Example, in cell I might have #define Some-preprocessor-name But I'd l...

Auto-Generate place holder format string for String.Format()

Is there a way to tell the String.Format() function (without writing my own function) how many placeholders there are dynamically? It we be great to say 15, and know I'd have {0}-{14} generated for me. I'm generate text files and I often have more than 25 columns. It would greatly help. OK, I will rephrase my question. I wanted to ...

Automatic Unicode string formatting in Java

I just came across something like this: String sample = "somejunk+%3cfoobar%3e+morestuff"; Printed out, sample looks like this: somejunk+<foobar>+morestuff How does that work? U+003c and U+003e are the Unicode codes for the less than and greater than signs, respectively, which seems like more than a coincidence, but I've never ...

(ASP.NET) How do I remove special characters when doing a DateTime.Now.ToString()

So I have a flashobject which I need to pass a formatted DateTime string to. My code: string date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); which outputs as: 2009-09-16 22:26:45 However when it is actually output to HTML and swfobject it renders it as: so.addVariable("inNowDate","2009-09-16+22%3a25%3a13"); I think this is m...

.NET Formatting strings - good practices for commenting?

Before .NET, we had our own phrase localization system and we built in a way for comments to be nested in the formatting string like: "{0:price}". I'm finding that I miss this more and more as the years go by. It doesn't appear that there is a way to document formatting strings in situ like this in .NET: string.Format("{0//numerator} ...

How do I correctly space multiple string fragments within a single bounding rectangle when priting with c#?

I am writing a function that applies special formatting to predetermined keywords when printing a string. For example, in the string - "Why won't this work?" I might need to print the word "Why" underlined and in blue. I've had to implement this in pieces, printing each segment of a string with a separate call to print. This approach w...

printf seems to be ignoring string precision

So, I'm a bit stymied. According to man 3 printf on my system, the string format "%5s" should use the specified precision to limit the number of characters printed from the string argument given. % man 3 printf PRINTF(3) BSD Library Functions Manual PRINTF(3) NAME printf, fprintf, sprintf, snprintf,...

how % applies to this method in Python?

From my studying of python, I've found two uses for %. It can be used as what's called a modulo, meaning it will divide the value to the left of it and the value to the right of it and spit back the remainder. The other use is a string formatter. So I can do something like 'Hi there %s' % name, where name is a list of names. Also, if y...

String Format Does Not Works For string

Hi, I have a serial number which is String type. Like This; String.Format("{0:####-####-####-####}", "1234567891234567" ); I need to see Like This, 1234-5678-9123-4567; Bu this Code does not work? Can you help me? ...

Convert double to String with fixed width

I want to convert a double to string with fixed width. If the width is 10, then I want the double value to get round off to this width. For example, if value = 102.121323435345 and width is 10, then this value should be, position==> 0123456789 value = 102.121323 I can achieve this with snprintf, but I am lo...

Formatting my string.

Hello, how can I format a string like this: string X = "'{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}'",???? I remember I used to be able to put a comma at the end and specify the actual data to assign to {0},{1}, etc. Any help? ...

datetime string issue in c#

Suppose I have following code to convert datetime to string: DateTime dt; //... string ds = dt.ToString("dd/MM/yyyy hh:mm") If the dt is 15/02/2009 08:22, I want to the string is 15/02/2009 08:22AM If the dt is 15/02/2009 20:22, I want to the string is 15/02/2009 08:22PM How to implement it? ...