Python like string format in typescript
Asked Answered
B

2

1

In python I can do following

print "%02d:%02d" % (9, 6) # will output 09:06

How can I do this in TypeScript?

Boring answered 4/10, 2016 at 13:52 Comment(0)
N
2

Use the sprintf-js library and types.

Natashianatassia answered 4/10, 2016 at 14:18 Comment(1)
This is actually very simple and elegant solution.Boring
C
0

FIDDLE: https://jsfiddle.net/1ytxfcwx/

NPM: https://www.npmjs.com/package/typescript-string-operations

GITHUB: https://github.com/sevensc/typescript-string-operations

Either use Template Strings -> https://basarat.gitbooks.io/typescript/content/docs/template-strings.html

or you can use a class a wrote -> String.Format not work in TypeScript

or use my NPM package!

https://www.npmjs.com/package/typescript-string-operations

var value = String.Format("{0:L}", "APPLE"); //output "apple"

Companionate answered 4/10, 2016 at 14:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.