!!!!!!!!!!!!提取ip地址!50分!分析字符串。(50分)

  • 主题发起人 sohuandsina
  • 开始时间
S

sohuandsina

Unregistered / Unconfirmed
GUEST, unregistred user!
var str1,str2,str3,str4,str5:string;
str1:="192.168.1.2";
怎么实现
str2:=192;
str3:=168;
str4:=1;
str5:=2;
帮帮我。
 
请给详细方法。我不会。谢谢。
 
i:=Pos('.',str1);
str2:=Copy(str1,1,i-1);
str1:=copy(str1,i+1,length(str1));

i:=Pos('.',str1);
str3:=Copy(str1,1,i-1);
str1:=copy(str1,i+1,length(str1));

i:=Pos('.',str1);
str4:=Copy(str1,1,i-1);

str5:=copy(str1,i+1,length(str1));

分太少了
 
这段代码应该合你用。
procedure SetAddress( const Value: String );
var str: String;
begin
str := Value;
try
FFirstIPAddress := StrToInt( Copy(str, 1, Pos('.', str) - 1) );
except
FFirstIPAddress := 0;
end;

try
str := Copy( str, Pos('.', str) + 1, 255 );
FSecondIPAddress := StrToInt( Copy(str, 1, Pos('.', str) - 1) );
except
FSecondIPAddress := 0;
end;

try
str := Copy( str, Pos('.', str) + 1, 255 );
FThirdIPAddress := StrToInt( Copy(str, 1, Pos('.', str) - 1) );
except
FThirdIPAddress := 0;
end;

try
str := Copy( str, Pos('.', str) + 1, 255 );
FFourthIPAddress := StrToInt( str );
except
FFourthIPAddress := 0;
end;
end;
 

Similar threads

顶部