将数字转换为指定格式的字符串

问题描述:

我需要一个像下面这样的函数,它应该有2个输入数字和一个字符串格式



例如





I need a function like below which should have 2 inputs a number and a string format

for example


string ConvertnumbertoString(string sFormat,int number)
{
return convertedstring
}





如果我调用这样的函数ConvertnumbertoString( $$$$$ 281

然后我的输出应 00281



更多样品



&&&& 15 = 0015

&&&&& 15 = 00015

$ 15 = 15




我怎么能这样做...请帮助我



if i call function like this ConvertnumbertoString("$$$$$",281)
then my output should be 00281

some more samples

&&&& 15 = 0015
&&&&& 15 = 00015
$ 15 = 15


How can i do this..please help me

281

然后我的输出应 00281



更多样品



&&&& 15 = 0015 >
&&&& 15 = 00015
",281)
then my output should be 00281

some more samples

&&&& 15 = 0015
&&&&& 15 = 00015


15 = 15



我该怎么办...请帮助我
15 = 15

How can i do this..please help me


您好,



看看这里:

标准数字格式字符串 [ ^ ]

自定义数字格式字符串 [ ^ ]

如何:使用前导零填充数字 [ ^ ]

Int [C#]的字符串格式 [ ^ ]
Hi,

Have a look here:
Standard Numeric Format Strings[^]
Custom Numeric Format Strings[^]
How to: Pad a Number with Leading Zeros[^]
String Format for Int [C#][^]