Convert int to string with leading zeros in Swift
In this post we will give you information about Convert int to string with leading zeros in Swift. Hear we will give you detail about Convert int to string with leading zeros in SwiftAnd how to use it also give you demo for it if it is necessary.
we are going to learn about how to convert a int(Integer) to string with leading zeros in Swift.
To convert int to a string by adding leading zeros, we can use the Strings init(format:_:) initializer.
Here is an example, that adds leading 0 to the 1.
import Foundationlet str1 = String(format: "%02d", 1);print(str1);
Output:
01
If you want to add two leading zeros, you can do it like this.
import Foundationlet string0 = String(format: "%03d", 1);print(string0); // 001
Hope this code and post will helped you for implement Convert int to string with leading zeros in Swift. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs