开发者

crystal reports : character "." in domain string errors

My goal is the discern whether the domain has a subdomain or not by counting the number of periods there are in the domain name. If it has 2 periods, there is obviously a subdomain. I have the following crystal reports formula written in crystal syntax

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
    开发者_C百科 (
        count := count + 1; 
        if count = 2 then (
            pos2 := i
        );

       ); 
);
if count > 1 then 
left({?domain}, pos2)
else 
left({?domain},instr({?domain}, ".")-1)

any ideas? hopefully this is something my tired eyes are just glazing over.

UPDATE: here is the weird thing that happens. If I add "+ totext(pos2)

if count > 1 then 
    left({?domain}, pos2) + totext(pos2)
    else 
    left({?domain},instr({?domain}, ".")-1)

it outputs correctly subdomain.domain with the .com removed

if i run it without the totext(pos2)

if count > 1 then 
    left({?domain}, pos2)
    else 
    left({?domain},instr({?domain}, ".")-1)

it only shows the subdomain part of subdomain.domain.com Any ideas why?


Should there be a final ; on the last line?

Alternatively, have you considered making the entire formula something like:

Left({?domain},InStrRev({?domain}, ".")-1)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜