問一行看不懂的語法 |
尚未結案
|
wena
一般會員 發表:26 回覆:37 積分:12 註冊:2005-07-20 發送簡訊給我 |
int row = 6; // 要處理的資料行數 (Row)
int col = 12; // 要處理的資料行位置 (Column)
AnsiString temp = RichEdit2->Lines->Strings[row];
if (MaskEdit1->Text.Length() > 0) {
int len = temp.Length();
if(len < col){
RichEdit2->Lines->Strings[row] = temp + AnsiString::StringOfChar(' ', col - len);
}
temp = temp.SubString(1, col-1) + "%"+MaskEdit1->Text + temp.SubString(col+oldlen, temp.Length()-((col+oldlen)-1));
oldlen = MaskEdit1->Text.Length() + 1;
} else {
temp = temp.SubString(1, col-1) + temp.SubString(col+oldlen, temp.Length()-((col+oldlen)-1));
oldlen = 0;
}
RichEdit2->Lines->Strings[row] = temp; 這是同學給的一個插入程式,想請問:
>>
|
taishyang
站務副站長 發表:377 回覆:5490 積分:4563 註冊:2002-10-08 發送簡訊給我 |
|
RedSnow
版主 發表:79 回覆:1322 積分:845 註冊:2003-12-15 發送簡訊給我 |
wena 您好: 在您擷取資料的原文裡,我有加上註解如下:
.... 前略 .... // 先確認資料行有足夠數量的長度 AnsiString temp = RichEdit1->Lines->Strings[9]; int len = temp.Length(); if (len < 5) { // 若資料行少於 5 個字元,則以空白字元補足 RichEdit1->Lines->Strings[9] = temp AnsiString::StringOfChar(' ', 5 - len); } .... 後略 ....而 BCB 的 Help 對該函式的說明與範例如下: Description Returns a string with the specified number of characters. static AnsiString __fastcall StringOfChar(char ch, int count); Returns a string containing count characters with the character value given by ch. For example, AnsiString s = AnsiString::StringOfChar('A', 10); sets s to the string 'AAAAAAAAAA'. 因此您可以知道,RichEdit2->Lines->Strings[row] = temp AnsiString::StringOfChar(' ', col - len); 這一行的意義如下: 將 RichEdit2 的第 row 個資料行的內容設為 temp 字串的內容再加上 col - len 個數量的空白字元。 7 天天敲鍵盤 v 時時按滑鼠 8 |
wena
一般會員 發表:26 回覆:37 積分:12 註冊:2005-07-20 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |