0
我的目標是通過計算域名中有多少個句點來辨別域名是否具有子域名。如果它有兩個時期,顯然有一個子域。 我有以下的水晶報表公式寫在Crystal語法水晶報告:字符「。」在域名字符串錯誤
local numbervar count :=0;
Local numbervar strLen := length({?domain});
local stringvar c := {?domain};
local numbervar i;
local numbervar pos2 :=0;
for i:=1 to strLen do
( if Mid({?domain}, i, 1) = "." then
(
count := count + 1;
if count = 2 then (
pos2 := i
);
);
);
if count > 1 then
left({?domain}, pos2)
else
left({?domain},instr({?domain}, ".")-1)
什麼想法?希望這是我累了的眼睛只是在上釉。
更新:這是發生的奇怪的事情。 如果我添加「+ totext(POS2)
if count > 1 then
left({?domain}, pos2) + totext(pos2)
else
left({?domain},instr({?domain}, ".")-1)
它輸出正確地與.COM subdomain.domain除去
如果我運行它沒有totext(POS2)
if count > 1 then
left({?domain}, pos2)
else
left({?domain},instr({?domain}, ".")-1)
它只顯示subdomain.domain.com的子域部分 任何想法爲什麼?
FYI,「伯爵」是水晶受控串whatchamacallit。作爲良好的編程習慣,我建議將您的變量重命名爲「tot」或「cnt」或「all」或「total」。 – PowerUser 2010-09-01 15:13:32
另外,abs()是否必要?我只是無法看到pos2會消極的任何情況。 – PowerUser 2010-09-01 15:20:02