我在EDIT中输入一串带空格的数字(例如:12 45 44 54 8 2)如何统计出数值的平均值(是指有空格隔开的数值和的平均值,数值的个数不确定是随意输入的)
解决方案 »
- Memo中获得鼠标选中的字符串
- 如何把浮点型转换为整型?
- 帮个忙!看看这段赋值为什么会出错!
- 在函數與過程裡中止其執行用什麼命令?
- 隐藏进程的问题??(在线等待,500分向你招手哟)
- 为什么我在程序运行中改变ADOQuery的SQL,open后不能正常执行,而我在程序设计中写入同样的SQL语句执行正常?
- 字符串格式化的问题;在线!!!!!!!!!
- 急呀,请问哪里有《delphi com 深入编程》这本书下载
- 再次请教高手们:请教在PARADOX表中增加一个BZ字段,此字段是备注型的?
- Win7 下 为什么 playsound那么慢。
- 如何用动态TQUERY动态生成TDECISION CUBE的字段及TDECISION GRAPH ???
- 如何用动态TQUERY动态生成TDECISION CUBE的字段及TDECISION GRAPH ???
const List: TStrings);
var
I, L: Integer;
Left: AnsiString;
begin
Assert(List <> nil);
List.Clear;
L := Length(Sep);
I := Pos(Sep, S);
while (I > 0) do
begin
Left := LeftStr(S, I - 1);
List.Add(Left);
Delete(S, 1, I + L - 1);
I := Pos(Sep, S);
end;
if S <> '' then
List.Add(S);
end;
s: string;
i, sum: Integer;
strs: TStrings;s := "12 45 44 54 8 2";
strs := TStringList.Create;
StrToStrings(s, " ", strs);
sum := 0;
for i := 0 to strs.Count - 1 do
sum := sum + StrToInt(strs[i]);
Result := sum / strs.Count
count,x,y,sum:integer;
s:string;
begin
x:=0;
count:=0;
sum:=0;
s:=Edit1.Text;
while(length(trim(s))>0) do
begin
y:=pos(' ',s);
if (y=0) then
begin
sum:=strtoint(s)+sum;
count:=count+1;
showmessage('平局数= '+floattostr(sum/count) +' and sum= '+inttostr(sum));
break;
end
else
begin
sum:=strtoint(trim(copy(s,1,y)))+sum;
s:=copy(s,y+1,length(s)-y);
count:=count+1;
end;
s:=trim(s);
end