本文整理匯總了C#中System.Random.PadLeft方法的典型用法代碼示例。如果您正苦於以下問題:C# Random.PadLeft方法的具體用法?C# Random.PadLeft怎麽用?C# Random.PadLeft使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Random
的用法示例。
在下文中一共展示了Random.PadLeft方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: CreateCode
private string CreateCode()
{
var code = new Random().Next(1, 999999).ToString();
code = code.PadLeft(6, '0');
return code;
}
示例2: CreateBackup
/// <summary>
/// Creates a copy of the given file, inserting a number between the
/// filename and extension
/// </summary>
/// <param name="file">The file to create a copy of</param>
/// <returns>The full name of the copy</returns>
private static string CreateBackup(FileInfo file)
{
string theDirName = file.DirectoryName;
string theFileNameNoExt = System.IO.Path.GetFileNameWithoutExtension(file.Name);
string theExt = file.Extension;
string theRandom = new Random().Next().ToString();
theRandom = theRandom.PadLeft(5, '0');
theRandom = theRandom.Substring(theRandom.Length - 5);
string theBackupName = theDirName + System.IO.Path.DirectorySeparatorChar
+ theFileNameNoExt + "." + theRandom + theExt;
File.Copy(file.FullName, theBackupName, true);
return theBackupName;
}
示例3: Init
/// <summary>
/// 初始化
/// </summary>
private void Init()
{
if (string.IsNullOrEmpty(this.logginName))
{
this.logginName = "DefaultZhu";
}
string ret = string.Empty;
ret = this.logginName;
if (ret.Length <= 10)
{
ret = ret.PadLeft(10, '6');
}
else
{
ret = ret.Substring(ret.Length - 10, 10);
}
string timeStr = DateTime.Now.ToString("yyMMddHHmmssfff");
string randomCodeStr = new Random().Next(0, 99999).ToString();
if (randomCodeStr.Length < 5)
{
randomCodeStr = randomCodeStr.PadLeft(5, '0');
}
this.trackId = ret + timeStr + randomCodeStr;
}