2014年1月24日 星期五

日期相差多少年、月、日、時、分、秒

procedure TForm1.BitBtn1Click(Sender: TObject);
var
  a,b: Tdatetime;
  c: string;
begin
  a:=2007/3/13;
  b:=2006/3/2;
  c := '';
  if (daysbetween(a,b) div 30) <> 0 then
    c := inttostr(daysbetween(a,b) div 30)+'個月';

  if ((daysbetween(a,b) mod 30) <> 0)and ((daysbetween(a,b) div 30) <> 0)then
    c := c + '又' + inttostr(daysbetween(a,b) mod 30)+'天'
  else if (daysbetween(a,b) mod 30) <> 0 then
    c := inttostr(daysbetween(a,b) mod 30)+'天';

  showmessage(c);
  showmessage(inttostr(yearsbetween(a,b))+'年');
  showmessage(inttostr(monthsbetween(a,b))+'月');
  showmessage(inttostr(daysbetween(a,b))+'天');
  showmessage(inttostr(hoursbetween(a,b))+'小時');
  showmessage(inttostr(minutesbetween(a,b))+'分鐘');
  showmessage(inttostr(secondsbetween(a,b))+'秒');  
end;

檔案編碼列表

'jp2'=>'0000000C6A502020',
'3gp'=>'0000002066747970',
'3gp5'=>'0000001866747970',
'm4a'=>'00000020667479704D3441',
'ico'=>'00000100',
'spl'=>'00000100',
'vob'=>'000001BA',
'cur'=>'00000200',
'wb2'=>'00000200',
'wk1'=>'0000020006040600',
'wk3'=>'00001A0000100400',
'wk4'=>'00001A0002100400',
'wk5'=>'00001A0002100400',
'123'=>'00001A00051004',
'qxd'=>'00004D4D585052',
'mdf'=>'010F0000',
'tr1'=>'0110',
'rgb'=>'01DA01010003',
'drw'=>'07',
'dss'=>'02647373',
'dat'=>'A90D000000000000',
'db3'=>'03',
'qph'=>'03000000',
'adx'=>'80000020031204',
'db4'=>'04',
'n'=>'FFFE0000',
'a'=>'FFFE0000',
'skf'=>'07534B46',
'dtd'=>'0764743264647464',
'db'=>'D0CF11E0A1B11AE1',
'pcx'=>'0A050101',
'mp'=>'0CED',
'doc'=>'D0CF11E0A1B11AE1',
'nri'=>'0E4E65726F49534F',
'wks'=>'FF00020004040554',
'pf'=>'1100000053434341',
'ntf'=>'4E49544630',
'nsf'=>'4E45534D1A01',
'arc'=>'41724301',
'pak'=>'5041434B',
'eth'=>'1A350100',
'mkv'=>'1A45DFA393428288',
'ws'=>'1D7D',
'gz'=>'1F8B08',
'tar.z'=>'1FA0',
'ain'=>'2112',
'lib'=>'213C617263683E0A',
'msi'=>'D0CF11E0A1B11AE1',
'vmdk'=>'4B444D',
'dsp'=>'23204D6963726F73',
'amr'=>'2321414D52',
'hdr'=>'49536328',
'sav'=>'24464C3240282329',
'eps'=>'C5D0D3C6',
'pdf'=>'25504446',
'fdf'=>'25504446',
'hqx'=>'2854686973206669',
'log'=>'2A2A2A2020496E73',
'ivr'=>'2E524543',
'rm'=>'2E524D46',
'rmvb'=>'2E524D46',
'ra'=>'2E7261FD00',
'au'=>'646E732E',
'cat'=>'30',
'evt'=>'300000004C664C65',
'asf'=>'3026B2758E66CF11',
'wma'=>'3026B2758E66CF11',
'wmv'=>'3026B2758E66CF11',
'wri'=>'BE000000AB',
'7z'=>'377ABCAF271C',
'psd'=>'38425053',
'sle'=>'414376',
'asx'=>'3C',
'xdr'=>'3C',
'dci'=>'3C21646F63747970',
'manifest'=>'3C3F786D6C2076657273696F6E3D',
'xml'=>'3C3F786D6C2076657273696F6E3D22312E30223F3E',
'msc'=>'D0CF11E0A1B11AE1',
'fm'=>'3C4D616B65724669',
'mif'=>'56657273696F6E20',
'gid'=>'4C4E0200',
'hlp'=>'4C4E0200',
'dwg'=>'41433130',
'syw'=>'414D594F',
'abi'=>'414F4C494E444558',
'aby'=>'414F4C4442',
'bag'=>'414F4C2046656564',
'idx'=>'5000000020000000',
'ind'=>'414F4C494458',
'pfc'=>'414F4C564D313030',
'org'=>'414F4C564D313030',
'vcf'=>'424547494E3A5643',
'bin'=>'424C4932323351',
'bmp'=>'424D',
'dib'=>'424D',
'prc'=>'424F4F4B4D4F4249',
'bz2'=>'425A68',
'tar.bz2'=>'425A68',
'tbz2'=>'425A68',
'tb2'=>'425A68',
'rtd'=>'43232B44A4434DA5',
'cbd'=>'434246494C45',
'iso'=>'4344303031',
'clb'=>'434F4D2B',
'cpt'=>'43505446494C45',
'cru'=>'43525553482076',
'swf'=>'465753',
'ctf'=>'436174616C6F6720',
'dms'=>'444D5321',
'adf'=>'5245564E554D3A2C',
'dvr'=>'445644',
'ifo'=>'445644',
'cdr'=>'52494646',
'vcd'=>'454E545259564344',
'mdi'=>'4550',
'e01'=>'4C5646090D0AFF00',
'evtx'=>'456C6646696C6500',
'qbb'=>'458600000600',
'cpe'=>'464158434F564552',
'flv'=>'464C56',
'aiff'=>'464F524D00',
'eml'=>'582D',
'gif'=>'47494638',
'pat'=>'47504154',
'gx2'=>'475832',
'sh3'=>'4848474231',
'tif'=>'4D4D002B',
'tiff'=>'4D4D002B',
'mp3'=>'494433',
'koz'=>'49443303000000',
'crw'=>'49491A0000004845',
'cab'=>'4D534346',
'lit'=>'49544F4C49544C53',
'chi'=>'49545346',
'chm'=>'49545346',
'jar'=>'5F27A889',
'jg'=>'4A47040E000000',
'kgb'=>'4B47425F61726368',
'shd'=>'68490000',
'lnk'=>'4C00000001140200',
'obj'=>'80',
'pdb'=>'ACED000573720012',
'mar'=>'4D41723000',
'dmp'=>'504147454455',
'hdmp'=>'4D444D5093A7',
'mls'=>'4D563243',
'mmf'=>'4D4D4D440000',
'nvram'=>'4D52564E',
'ppz'=>'4D534346',
'snp'=>'4D534346',
'tlb'=>'4D53465402000100',
'dvf'=>'4D535F564F494345',
'msv'=>'4D535F564F494345',
'mid'=>'4D546864',
'midi'=>'4D546864',
'dsn'=>'4D56',
'com'=>'EB',
'dll'=>'4D5A',
'drv'=>'4D5A',
'exe'=>'4D5A',
'pif'=>'4D5A',
'qts'=>'4D5A',
'qtx'=>'4D5A',
'sys'=>'FFFFFFFF',
'acm'=>'4D5A',
'ax'=>'4D5A900003000000',
'cpl'=>'DCDC',
'fon'=>'4D5A',
'ocx'=>'4D5A',
'olb'=>'4D5A',
'scr'=>'4D5A',
'vbx'=>'4D5A',
'vxd'=>'4D5A',
'386'=>'4D5A',
'api'=>'4D5A900003000000',
'flt'=>'76323030332E3130',
'zap'=>'4D5A90000300000004000000FFFF',
'sln'=>'4D6963726F736F66742056697375616C',
'jnt'=>'4E422A00',
'jtp'=>'4E422A00',
'cod'=>'4E616D653A20',
'dbf'=>'4F504C4461746162',
'oga'=>'4F67675300020000',
'ogg'=>'4F67675300020000',
'ogv'=>'4F67675300020000',
'ogx'=>'4F67675300020000',
'dw4'=>'4F7B',
'pgm'=>'50350A',
'pax'=>'504158',
'pgd'=>'504750644D41494E',
'img'=>'EB3C902A',
'zip'=>'504B0304140000',
'docx'=>'504B030414000600',
'pptx'=>'504B030414000600',
'xlsx'=>'504B030414000600',
'kwd'=>'504B0304',
'odt'=>'504B0304',
'odp'=>'504B0304',
'ott'=>'504B0304',
'sxc'=>'504B0304',
'sxd'=>'504B0304',
'sxi'=>'504B0304',
'sxw'=>'504B0304',
'wmz'=>'504B0304',
'xpi'=>'504B0304',
'xps'=>'504B0304',
'xpt'=>'5850434F4D0A5479',
'grp'=>'504D4343',
'qemu'=>'514649',
'abd'=>'5157205665722E20',
'qsd'=>'5157205665722E20',
'reg'=>'FFFE',
'sud'=>'52454745444954',
'ani'=>'52494646',
'cmx'=>'52494646',
'ds4'=>'52494646',
'4xm'=>'52494646',
'avi'=>'52494646',
'cda'=>'52494646',
'qcp'=>'52494646',
'rmi'=>'52494646',
'wav'=>'52494646',
'cap'=>'58435000',
'rar'=>'526172211A0700',
'ast'=>'5343486C',
'shw'=>'53484F57',
'cpi'=>'FF464F4E54',
'sit'=>'5374756666497420',
'sdr'=>'534D415254445257',
'cnv'=>'53514C4F434F4E56',
'cal'=>'B5A2B0B3B3B0A5B5',
'info'=>'E310000100000000',
'uce'=>'55434558',
'ufa'=>'554641C6D2C1',
'pch'=>'564350434830',
'ctl'=>'56455253494F4E20',
'ws2'=>'575332303030',
'lwp'=>'576F726450726F',
'bdr'=>'5854',
'zoo'=>'5A4F4F20',
'ecf'=>'5B47656E6572616C',
'vcw'=>'5B4D535643',
'dun'=>'5B50686F6E655D',
'sam'=>'5B7665725D',
'cpx'=>'5B57696E646F7773',
'cfg'=>'5B666C7473696D2E',
'cas'=>'5F434153455F',
'cbk'=>'5F434153455F',
'arj'=>'60EA',
'vhd'=>'636F6E6563746978',
'csh'=>'6375736800000002',
'p10'=>'64000000',
'dex'=>'6465780A30303900',
'dsw'=>'64737766696C65',
'flac'=>'664C614300000022',
'dbb'=>'6C33336C',
'acd'=>'72696666',
'ram'=>'727473703A2F2F',
'dmg'=>'78',
'lgc'=>'7B0D0A6F20',
'lgd'=>'7B0D0A6F20',
'pwi'=>'7B5C707769',
'rtf'=>'7B5C72746631',
'psp'=>'7E424B00',
'wab'=>'9CCBCB8D1375D211',
'wpf'=>'81CDAB',
'png'=>'89504E470D0A1A0A',
'aw'=>'8A0109000000E108',
'hap'=>'91334846',
'skr'=>'9501',
'gpg'=>'99',
'pkr'=>'9901',
'qdf'=>'AC9EBD8F0000',
'pwl'=>'E3828596',
'dcx'=>'B168DE3A',
'tib'=>'B46E6844',
'acs'=>'C3ABCDAB',
'lbk'=>'C8007900',
'class'=>'CAFEBABE',
'dbx'=>'CFAD12FE',
'dot'=>'D0CF11E0A1B11AE1',
'pps'=>'D0CF11E0A1B11AE1',
'ppt'=>'D0CF11E0A1B11AE1',
'xla'=>'D0CF11E0A1B11AE1',
'xls'=>'D0CF11E0A1B11AE1',
'wiz'=>'D0CF11E0A1B11AE1',
'ac_'=>'D0CF11E0A1B11AE1',
'adp'=>'D0CF11E0A1B11AE1',
'apr'=>'D0CF11E0A1B11AE1',
'mtw'=>'D0CF11E0A1B11AE1',
'opt'=>'D0CF11E0A1B11AE1',
'pub'=>'D0CF11E0A1B11AE1',
'rvt'=>'D0CF11E0A1B11AE1',
'sou'=>'D0CF11E0A1B11AE1',
'spo'=>'D0CF11E0A1B11AE1',
'vsd'=>'D0CF11E0A1B11AE1',
'wps'=>'D0CF11E0A1B11AE1',
'ftr'=>'D20A0000',
'arl'=>'D42A',
'aut'=>'D42A',
'wmf'=>'D7CDC69A',
'efx'=>'DCFE',
'one'=>'E4525C7B8CD8A74D',
'rpm'=>'EDABEEDB',
'gho'=>'FEEF',
'ghs'=>'FEEF',
'wp'=>'FF575043',
'wpd'=>'FF575043',
'wpg'=>'FF575043',
'wpp'=>'FF575043',
'wp5'=>'FF575043',
'wp6'=>'FF575043',
'jfif'=>'FFD8FF',
'jpe'=>'FFD8FF',
'jpeg'=>'FFD8FF',
'jpg'=>'FFD8FF',
'mof'=>'FFFE23006C006900',
'ipa'=>'504B03040A',

delphi操作Excel

//Excel篇
mExcel.DisplayAlerts := False;                                  //Disable 提示訊息
mExcel.Visible := True;                                         //顯示 Excel 畫面
mExcel.ActiveWindow.FreezePanes := True;                        //凍結窗格(上一行一定要先選列或格)
mExcel.ActiveWindow.Zoom := 75;                                 //顯示比率為75%
mExcel.ActiveWindow.Zoom := True;                               //依據目前選擇範圍自動決定視窗大小

//Workbook篇
mWorkBook := mExcel.WorkBooks[1];                               //將指定變數設定第一個活頁簿(數字可以用名稱取代)
mWorkBook.Name :='內容';                                        //變更WorkBook名稱
mExcel.WorkBooks.Add;                                           //新增一個空白活頁簿
mExcel.WorkBooks.Open(完整路徑);                                //開啟Excel檔
mExcel.WorkBooks[mFile].Close;                                  //關閉Excel檔
DeleteFile(mPath+mFile);                                        //刪除Excel檔
mWorkBook.SaveAs(mPath+mFile,-4143);                            //儲存Excel檔

//Sheet篇
mSheet := mExcel.WorkBooks[1].WorkSheets[1];                    //將指定變數設定第一個工作表(數字可以用名稱取代)
mSheet.Name :='內容';                                           //變更Sheet名稱
mSheet.Copy[After := mWorkBook.Sheets[mWorkBook.Sheets.Count]]; //將mSheet複製到mWorkBook最後
mSheet.Move[After := mWorkBook.Sheets[mWorkBook.Sheets.Count]]; //將mSheet搬移到mWorkBook最後
mWorkbook.Sheets.Add[After:=mWorkbook.Sheets[mSheetCount-1]];   //新增一個空白工作表
mWorkBook.Sheets[1].Delete;                                     //刪除指定Sheet
mWorkBook.Sheets[1].Activate;                                   //將指定Sheet設為使用中

//刪除多餘Sheet
if (mWorkBook.Sheets.Count > 1) then
begin
  for i:=2 to mWorkBook.Sheets.Count do
    mWorkBook.Sheets[2].Delete;
end;

//選取篇
mSheet.Cells.EntireColumn                                       //所有欄
mSheet.Cells.EntireRow                                          //所有列
mSheet.Cells                                                    //所有儲存格
mSheet.Columns[1]                                               //第一欄
mSheet.Rows[1]                                                  //第一列
mSheet.Cells[r,c]                                               //第r列第c欄
mSheet.Range[起,迄]                                             //區間選擇(起訖可以是欄、列、格)

//填值篇
mSheet.Cells[1,1].Value:= '內容';                               //欄位填值
mSheet.Cells[1,1].Formula:= '公式';                             //欄位填入公式
mSheet.Cells[1,1].FormulaR1C1:= '公式';                         //欄位填入公式
mSheet.Cells[1,1].HasFormula                                    //儲存格是否有公式

//格式篇
mSheet.Range[起,迄].Merge;                                      //合併儲存格
mSheet.Cells.EntireColumn.AutoFit;                              //最適欄寬
mSheet.Cells.EntireRow.AutoFit;                                 //最適列高
mSheet.Columns[1].ColumnWidth := 100;                           //設定欄寬
mSheet.Rows[1].RowHeight := 100;                                //設定列高
mSheet.Rows[1].HorizontalAlignment := -4108;                    //水平置中(靠左:-4131;靠右:-4152)
mSheet.Rows[1].VerticalAlignment := -4108;                      //垂直置中(靠左:-4131;靠右:-4152)
mSheet.Rows[1].WrapText  := True;                               //自動換列
mSheet.Columns[1].Hidden := True;                               //隱藏

mSheet.Columns[1].NumberFormatLocal := '@';                     //設定欄位格式[文字]
mSheet.Columns[1].NumberFormatLocal := '#,##0_ ';               //設定欄位格式[數值(整數位 三位一撇)]
mSheet.Columns[1].NumberFormatLocal := '#,##0_ ;[紅色]-#,##0 '; //設定欄位格式[數值(整數位 三位一撇 負數紅字)]
mSheet.Columns[1].NumberFormatLocal := '#,##0_);[紅色](#,##0)'; //設定欄位格式[數值(整數位 三位一撇 負數括號紅字)]
mSheet.Columns[1].NumberFormatLocal := '0.00_ ';                //設定欄位格式[數值(小數兩位)]
mSheet.Columns[1].NumberFormatLocal := '0.0_);[紅色](0.0)';     //設定欄位格式[數值(小數一位 負數紅字)]
mSheet.Columns[1].NumberFormatLocal := '0.00%';                 //設定欄位格式[百分比(小數兩位)]

mSheet.Cells[1].Interior.ColorIndex := 38;                      //設定底色為玫瑰色
mSheet.Cells[1].Interior.ColorIndex := 6;                       //設定底色為黃色
mSheet.Cells[1].Interior.ColorIndex := 36;                      //設定底色為淺黃色
mSheet.Cells[1].Interior.ColorIndex := 35;                      //設定底色為淺綠色

mSheet.Cells[1,1].Font.Size := 10;                              //設定字體大小
mSheet.Cells[1,1].Font.Bold := True;                            //設定粗體字
......

//框線
mSheet.Cells[1,1].Borders[n].LineStyle := 1;
mSheet.Cells[1,1].Borders[n].Weight := 2;
//n = 5.左上右下斜線 6.左下右上斜線 7.左邊線 8.上邊線 9.下邊線 10.右邊線 11.垂直線 12.水平線
//Borders可使用參數:
// LineStyle = 1 實線;-4115 短虛線;4 長短虛線;5 長短短虛線;-4118 細虛線;-4119 雙實線
// Weight =  由細到粗:1 --> 2 --> -4138 --> 4
// ColorIndex = 顏色

//設定格式化條件
mSheet.Cells[1,1].FormatConditions.Delete;                      //清除格式化條件
mSheet.Cells[1,1].FormatConditions.Add[Type:='1', Operator:='1', Formula1:='1', Formula2:='2']; //新增格式化條件(最多3個)
//參數說明
//  參數   中文說明                                  說明
//======== ======== =======================================================================
//Type     來源型態 1.儲存格的值 2.公式
//Operator 規則     1.介於 2.不介於 3.等於 4.不等於 5.大於 6.小於 7.大於或等於 8.小於或等於
//Formula1 條件起
//Formula2 條件迄
mSheet.Cells[1,1].FormatConditions(1).Interior.ColorIndex := 3; //設定條件一為底色紅色
//可設定之格式有:Fonts(字型)、Borders(外框)、Interior(圖樣)

//資料篇
mSheet.Cells.EntireColumn.AutoFilter;                           //自動篩選

mExcel.Selection.Subtotal(1,-4157,VarArrayOf([4,5,6,7,8]),True,False,True);  //做小計
//參數說明
//      參數               中文說明         預設值
//================ ======================== ======
//GroupBy          分組小計欄位             1
//Function         使用函數                 -4157 加總
//TotalList        新增小計位置
//Replace          取代目前小計             True
//PageBreaks       每組資料分頁             False
//SummaryBelowData 摘要資料置於小計資料下方 True
//可使用函數:-4157 加總;-4106 平均值;-4112 項目個數;-4113 數字項目數;-4136 最大值;-4139 最小值;

mSheet.Outline.ShowLevels(2);                                    //把小計層級設2顯示

//列印篇
mSheet.PageSetup.PrintTitleRows := '$1:$1';                      //列印標題列
mSheet.PageSetup.CenterHeader := '表頭';                         //中頁首
mSheet.PageSetup.LeftHeader   := '頁次: &P / &N';                //左頁首
mSheet.PageSetup.RightHeader  := '';                             //右頁首
mSheet.PageSetup.CenterFooter := '& &P / &N';                   //中頁尾
mSheet.PageSetup.LeftFooter   := '頁次: &P / &N';                //左頁尾
mSheet.PageSetup.RightFooter  := '';                             //右頁尾
mSheet.PageSetup.PrintArea := '$B$1:$N$300';                     //設定列印範圍
mSheet.PageSetup.Orientation := 2;                               //1.直印 2.橫印
mSheet.PageSetup.Zoom := 65;                                     //列印時小成65%
mSheet.PageSetup.Zoom := True;                                   //使用頁次縮放功能
mSheet.PageSetup.FitToPagesWide := 1;                            //縮放成一頁寬(需配合Zoom = True)
mSheet.PageSetup.FitToPagesTall := 1;                            //縮放成一頁高(需配合Zoom = True)
mSheet.PageSetup.PaperSize := 8;                                 //設定紙張大小 8:A3、9:A4
mSheet.PageSetup.TopMargin := 1/0.035;                           //頂邊距1cm
mSheet.PageSetup.BottomMargin := 1/0.035;                        //底邊距1cm
mSheet.PageSetup.LeftMargin := 1/0.035;                          //左邊距2cm
mSheet.PageSetup.RightMargin := 1/0.035;                         //右邊距2cm
mSheet.PageSetup.HeaderMargin := 1/0.035;                        //頁首1cm
mSheet.PageSetup.FooterMargin := 1/0.035;                        //頁尾1cm
mSheet.PageSetup.CenterHorizontally := True;                     //頁面水平居中
mSheet.PageSetup.CenterVertically := False;                      //頁面垂直居中

判斷某一日期是否小於現在


procedure TForm1.Button1Click(Sender: TObject);   
var  
  pDate : AnsiString;  
begin  
  pDate:='2007/11/01';  
  if strtodate(pDate) < strtodate(FormatDateTime('yyyy/mm/dd', Now)) then  
    showmessage(datetostr(now()));  
end;

讓視窗程式開啟時,位置在螢幕的中間偏上

通常是設定在position屬性=poScreenCenter,但是那個是正中間,對於一般人的眼睛視線應該是中間偏上比較息慣,所以你可以在FormShow時加入下列程式碼:
procedure TForm1.FormShow(Sender: TObject);   
begin   
   left := (screen.Width - Width) div 2//等寬   
   top :=  (screen.Height - Height)*1 div 3//高度偏上   
end

2014年1月23日 星期四

字串去空白

去前後的空白可使用 trim() 這個函數
要去掉中間的空白,就要使用 
function StringReplace ( const SourceString, OldPattern, NewPattern : string; Flags : TReplaceFlags ) : string

範例:把a改成the
var
  before, after : string;

begin
  // Try to replace all occurrences of a or A to THE
  before := 'This is a way to live A big life';

  after  := StringReplace(before, ' a ', ' THE ',
                          [rfReplaceAll, rfIgnoreCase]);
  ShowMessage('Before = '+before);
  ShowMessage('After  = '+after);
end;

  

字串基本處理 (參考書上所寫)

1CompareStr 比較兩字串的大小(大小寫視為不同),傳回第一個不相同字元 ASCII 碼的差,若字串完全相同,則傳回 0 (字串的編號從 1 開始)。 function CompareStr(const S1, S2 : string) : Integer;
傳回結果:
當 S1>S2 傳回大於 0 的整數
當 S1<S2 傳回小於 0 的整數
當 S1=S2 傳回 0
範例:
S1:='Delphi 6.0';
S2:='delphi 6.0';
if CompareStr(S1,S2)<>0 then
showMessage('大小寫被視為不同的!');
2CompareText比較兩字串的大小(大小寫視為相同),傳回第一個不相同字元 ASCII 碼的差function CompareText(const S1, S2:string) : Integer;
傳回結果:
當 S1>S2 傳回大於 0 的整數
當 S1<S2 傳回小於 0 的整數
當 S1=S2 傳回 0
範例:
S1:='Delphi';
S2:='delphi';
ResultFlag:=CompareText(S1,S2);
if ResultFlag <>
ShowMessage('Delphi <>
else if ResultFlag > 0 then
ShowMessage('Delphi > delphi')
else
ShowMessage('Delphi = delphi');
{Delphi = delphi}
3Length傳回字串 S 的長度function Length(S) : Integer;
範例:
S:='Delphi 6.0 讚 '; //中文算兩個Bytes,長度包含空白
ShowMessage(IntToStr(Length(S)));
{14}
4Concat傳回字串相加的結果。使用字串相加(+)運算子,亦有相同的效果,且執行速度較快function Concat(s1 [, s2, ..., sn ] : string) : string;
範例:
S1:='今天';
S2:='下雨';
ShowMessage(Concat(S1, S2));
{今天下雨}
5Insert將 Source 字串插入 S 字串的第 count 個字元位置(字串的編號從 1 開始)procedure Insert(Source : string; var S : string; Index : Integer);
範例:
S1:='I Love you!';
S2:=' don''t';
insert(S2, S1, 2);
showmessage(S1);
{I don't Love you!}
6Copy傳回 S 字串的第 Index 字元起,拷貝 Count 個字元(字串的編號從 1 開始)function Copy(S; Index, Count:Integer) : string;
範例:
S:='Delphi 2006 is good??!';
S:=Copy(S, 1, 11);
ShowMessage(S);
{Delphi 2006}
7Delete將 S 字串從第 Index 字元開始,刪除 Count 個字元(字串的編號從 1 開始)procedure Delete(var S : string; Index, Count : Integer);
範例:
S:='Delphi is good??!';
Delete(S, 15, 2);
ShowMessage(S);
{Delphi is good!}
8Pos傳回 Substr 字串於 S 字串的開始位置(字串的編號從 1 開始)function Pos(Substr : string; S : string) : Integer;
範例:
S:=' Delphi is good ';
while Pos(' ', S)>0 do
begin
i:=Pos(' ', S);
showmessage(inttostr(i));
S[i]:='_';
end;
{1, 8, 11, 16, 17}
9Trim清除字串前後的空白function Trim(const S : string) : string;
範例:
S1:=' Delphi 6.0 ';
ShowMessage(Trim(S1));
{'Delphi 6.0'}
10TrimLeft清除字串左邊的空白function TrimLeft(const S : string) : string;
範例:
S1:=' Delphi 6.0 ';
ShowMessage(TrimLeft(S1));
{'Delphi 6.0 '}
11TrimRight 清除字串右邊的空白function TrimRight(const S : string) : string;
範例:
S1:=' Delphi 6.0 ';
ShowMessage(TrimRight(S1));