计算字符串中某符号的个案,最好是系统中就有的函数。
比如字符串 1,2,3,4,5,6 计算,号的个案为5
比如字符串 1,2,3,4,5,6 计算,号的个案为5
解决方案 »
- 点击按钮时,使程序触发Ctrl+A(全选事件)
- sidebar for delphi2005
- BCB的工程中的form如何在 delphi 中使用?
- 在线程内调用DDE控件为什么总失败
- 导出到excel问题(急啊)
- delphi写的人事工资管理软件,出炉有一会儿了
- 紧急求助高手!!关于adoquery的sql语句引用问题
- dbgrid的数据保存的问题:dbgrid中一般是移开当前记录时才post的,如果直接关闭窗体时怎么保存数据呢?
- 如何编写一个支持拖放操作的ListBox,就是把文件拖放入ListBox时,ListBox显示这些文件的全路径+文件名
- 急!!!! help me
- 请教:图像叠加
- delphi统计代码的行数、其中含有注释内容的行数,空行行数
var
List: TStringList;
begin
List := TStringList.Create;
List.Delimiter := ',';
List.DelimitedText := '1,2,3,4,5,6';
ShowMessage(IntToStr(List.Count - 1)); // 5
List.Free;
end;
var
S :string;
i,Count :integer;
begin
S := '1,2,3,4,5,6';
Count := 0;
i := for 1 to Length(S) do
if S[i]=',' then
Count := Count + 1;
showmessage(',个数是:'+ IntToStr(Count));
end;
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TStringlist = class(Classes.TStringList)
private
FDuplicateCount:Integer; // 重复个数
FDuplicateStr:string; // 需要检查重复的字串
protected
function GetDuplicateCount:Integer;
public
constructor Create;
procedure Clear; override;
function AddObject(const S: string; AObject: TObject): Integer; override;
property DuplicateCount:Integer read GetDuplicateCount;
end; TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public end;var
Form1: TForm1;implementationuses RTLConsts;{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
v: TStringList;
s: string;
begin
s := '1,2,国,3,国,4,457,234,国,32,32,国,5667868';
v := TStringList.Create;
v.Sorted := True;
v.Duplicates := dupIgnore;
v.FDuplicateStr :='国';
v.Delimiter :=',';
v.DelimitedText := s;
ShowMessage(IntToStr(v.DuplicateCount));
v.Free;
end;{ TStringlist }function TStringlist.AddObject(const S: string; AObject: TObject): Integer;
begin
if not Sorted then
Result := Count
else
if Find(S, Result) then
case Duplicates of
dupIgnore:
begin
if s = FDuplicateStr then
Inc(FDuplicateCount);
Exit;
end;
dupError: Error(@SDuplicateString, 0);
end;
InsertItem(Result, S, AObject);
end;procedure TStringlist.Clear;
begin
inherited;
FDuplicateCount := 0;
end;constructor TStringlist.Create;
begin
inherited Create;
end;function TStringlist.GetDuplicateCount: Integer;
begin
Result := 0;
if FDuplicateCount = 0 then
begin
if IndexOf(FDuplicateStr) <> -1 then
Result := 1;
end else
begin
Result := FDuplicateCount + 1;
end;
end;end.
var
i: Integer;
begin
Result:= 0;
for i:=1 to Length(Str) do
if Copy(Str,i,Length(SubStr))=SubStr then
Inc(Result);
end;
function GetSubStrCount(const ASubStr, AStr: string): Integer;
begin
if ASubStr = '' then
Result := 0
else
Result := (Length(AStr) - Length(StringReplace(AStr, ASubStr, '', [rfReplaceAll]))) div Length(ASubStr)
end;
//调用:ShowMessage(IntTOStr(GetSubStrCount(',', '1,2,3,4,5,6 ')))