C 函式,PadLeft ,填充指定數量的空格。

2022-02-02 14:58:40 字數 1498 閱讀 3637

返回乙個新字串,該字串通過在此例項中的字元左側填充空格來達到指定的總長度,從而實現右對齊。

命名空間:system

程式集:mscorlib(在 mscorlib.dll 中)

public

string padleft(

int totalwidth)引數

totalwidth

型別:system.int32

結果字串中的字元數,等於原始字元數加上任何其他填充字元。

返回值型別:system.string

totalwidth.' data-guid="977d2be33ae19e5b331830b6b71a8368">與此例項等效的乙個新字串,但該字串為右對齊,因此,在左側填充所需數量的空格,使長度達到 totalwidth。

totalwidth is less than the length of this instance, a new string that is identical to this instance.' data-guid="a24b3b7fdec2f9e8d5e4f7346df95854">如果 totalwidth 小於此例項的長度,則為與此例項相同的新字串。

異常異常

條件argumentoutofrangeexception

totalwidth is less than zero. ' data-guid="62082aa38e0b25debcec82ce4d71d0fd">totalwidth 小於零。

備註unicode 空格定義為十六進製制的 0x20。

padleft(int32)

method pads the beginning of the returned string.' data-guid="4b73f6801fa2f286b9af3f3966aa87b6">padleft(int32)

方法填充返回字串的開頭。

這意味著當對從右向左的語言使用該方法時,它將填充字串的右部。

注意

此方法不修改當前例項的值。

totalwidth characters.' data-guid="90f394f4a985f68551cae0b36b0ff6d2">而是返回乙個新字串,其中填充了前導空白以使字串的總長度為 totalwidth 個字元。

示例padleft

method.' data-guid="deef2eeaac87826847f8ac3fa7cdf24e">下面的示例說明 padleft

方法。c#

string str = "bbq and slaw";

console.writeline(str.padleft(15)); // displays " bbq and slaw".

console.writeline(str.padleft(5)); // displays "bbq and slaw".

**msdn:

C 習題5 5 使用函式統計指定數字的個數

本題要求實現乙個統計整數中指定數字的個數的簡單函式。函式介面定義 int countdigit int number,int digit 其中number是不超過長整型的整數,digit為 0,9 區間內的整數。函式countdigit應返回number中digit出現的次數。裁判測試程式樣例 in...

lpad函式 用指定的字元進行填充

函式介紹 lpad函式從左邊對字串使用指定的字元進行填充。從其字面意思也可以理解,l是left的簡寫,pad是填充的意思,所以lpad就是從左邊填充的意思。語法格式如下 lpad string,padded length,pad string string 準備被填充的字串 padded lengt...

C 實現把指定資料寫入串列埠

p程式設計客棧ublic static bool write程式設計客棧toserialport bytebytearr catch exception ex finally 本例使用的是方法write bytebuffer,int32 offset,int32 count 該方法使用緩衝區的資料將...