在 Julia 中将整数转换为字符串 - 字符串()函数
字符串()是 julia 中的一个内置函数,用于将指定的整数转换为给定基数的字符串。
Syntax:
string(n::Integer; base::Integer, pad::Integer)
Parameters:
- n::Integer: Specified integer.
- base::Integer: Specified base in which conversion are going to be performed.
- pad::Integer: It is number of characters present in the returned string.
Returns: It returns the converted string in the given base.
示例 1:
Python
# Julia program to illustrate
# the use of String string() method
# Conversion of integer to a string
# in the given base
Println(string(10, base = 5, pad = 5))
Println(string(10, base = 5, pad = 3))
Println(string(5, base = 10, pad = 2))
Println(string(8, base = 9, pad = 4))
Python
# Julia program to illustrate
# the use of String string() method
# Creation of a single string using
# all the arguments
Println(string("A", 5, true))
Println(string("A", 10, false))
Println(string("B", 6, true))
Println(string("C", 12, false))
输出:
:
示例 2:
Python
# Julia program to illustrate
# the use of String string() method
# Creation of a single string using
# all the arguments
Println(string("A", 5, true))
Println(string("A", 10, false))
Println(string("B", 6, true))
Println(string("C", 12, false))
输出: