当前位置:首页 » 软件开发
开发技术指南» 文章正文
    引言: 相信字符串处理中用的最多的就是 Pos 函数了。
 

 

 ·自定义dataset,并写入数据    »显示摘要«
    摘要: 新建一 dataset , 并加入数据 : preparetablefunction tfrm_print.createtableinmemory(const afielddefs:tfielddefs):tdataset;var temptable:tclientdataset;begin temptable:=nil; result:=nil; if afielddefs<>ni......
 ·ini文件的读写    »显示摘要«
    摘要: function readinifile(filename,section,ident:string):string;? //读取配置文件var? ini:tinifile;begin? ini:=tinifile.create(filename);? result:=ini.readstring(section,ident,);? ini.free;end; procedure writei......


比 FastPos 还要快 Pos 函数

相信字符串处理中用的最多的就是 pos 函数了.但是如果要搜索一个字符串中第二次或者第三次出现的子字符串的,就没有现成的 delphi 标准函数了.所以我就自己写了一个.同时与网上比较流行的 faststrings.smartpos() 与 jvcl.npos() 做了比较,速度更快,而且兼容 unicode(widestring/widechar).

【程序编程相关:一个定时网络唤醒的Windows 200

【推荐阅读:Delphi单元文件详解

注:代码可能有人会觉得不太舒服,但作为最常用的字符串函数,这样的优化我觉得还是值得的. 【扩展信息:Delphi下用WindowsAPI创建

function quickpos(const substr, s: widestring; matchesindex: integer = 1): integer;

function quickposback(const substr, s: widestring; matchesreverseindex: integer = 1): integer;

代码如下:

// compares a substring with a string. *for inline use"

// c: 2004-07-05 | m: 2004-07-05

function _inlinecomparetext(const substr, s: widestring; startindex: integer = 1; lenofsubstr: integer = -1; lenofs: integer = -1): boolean;

var

? i: integer;

begin

? if lenofsubstr = -1 then lenofsubstr := length(substr);

? if lenofs = -1 then lenofs := length(s);

? if lenofsubstr > lenofs then

? begin

? ? result := false;

? ? exit;

? end;

? for i := 1 to lenofsubstr do

? ? if substr[i] s[i + startindex - 1] then


...   下一页
 ·组件制作之三(图形控件)    »显示摘要«
    摘要: vcl中的shape是个很不错的控件,可以选择几种图形,以满足我们的需求,但有时候就是觉得它的可选图形少了一点,比如我们想要一个三角形,它却没有。于是就想到来扩展一下这个控件,名为shapeex。其实扩展的功能不多,只是增加了一些图形。而类也并不是继承自tshape,而是继承自tgraphiccontrol,这样可以让我们彻底看看图形控件的做法。tshape也是继承自tgraphiccontro......
» 本期热门文章:

©2000-2007 All Rights Reserved. 最佳浏览:1024X768 MSIE