Javascript string formatting Tool

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.