Several programming extends ages implement a sprintf function, to output a formatted string. It originated from the C programming language, printf function. Its a string manipulation function.
This is limited sprintf Javascript implementation. function returns a string formatted by the usual printf conventions. see below for more details. you must specify the string and how to format the variables in it. possible format values:
- %-Returns a percent sign
- % B-binary number
- % C-the character according to the ASCII Value
- % D-Signed decimal number
- % F-floating-point number
- % O-octal number
- % S-string
- % X-hexadecimal number (lowercase letters)
- % X-hexadecimal number (uppercase letters)
Additional format values. These are placed between the % and the letter (example %. 2f ):
- + (Forces both + and-in front of numbers. By default, only negative numbers are marked)
- -(Left-justifies the variable value)
- 0 zero will be used for padding the results to the right string size
- [0-9] (specifies the minimum width held of to the variable value)
- . [0-9] (specifies the number of decimal digits or maximum String Length)
If you plan using UTF-8 encoding in your project don't forget to set the page encoding to UTF-8 (Content-Type meta tag), and use Javascript UTF-8 utility found on this website.
Link: http://www.webtoolkit.info/javascript-sprintf.html
Download:
Webtoolkit. sprintf. js
Http://download.csdn.net/source/1972105