0

我想将备忘录中填充的动态网关 IP 捕获到文本框中。如何使用通配符或捕获以“网关:10.127.*.*”开头的整行网关并将网关 IP 获取到文本框。

以下是已捕获的备忘录文本示例:

Description: Microsoft Hosted Network Virtual Adapter
HW Address Length: 6
HWAddress: E0:2A:82:F9:B2:3E
Index: 32
Type: 71
CurrentIPAddress: 
IP Addresses:    192.168.48.1/255.255.255.0
Gateway:    0.0.0.0/255.255.255.255
Name: {22712B8F-5E3A-48D4-8C0D-771708BF0305}
Description: HUAWEI Mobile Connect - Network Card
HW Address Length: 6
HWAddress: 0C:5B:8F:27:9A:64
Index: 4
Type: 243
CurrentIPAddress: 
IP Addresses:    10.127.144.193/255.255.255.252
Gateway:    10.127.144.194/255.255.255.255

编辑:(来自评论)

I:= Pos('Gateway: 10.127.', Memo1.Text);
if I > 0 then begin
   L := SendMessage(Memo1.Handle, EM_LINEFROMCHAR,   (intTostr(1));
   edit1.Text:=(intTostr(L)); 
4

2 回答 2

3

这是 René 答案的 Delphi 7 版本:

var
  ii: integer
begin
  for ii := 0 to memo.lines.count -1 do begin
    if pos('Gateway:   10.127.', memo.lines[ii]) > 0 then begin
      textbox.caption := memo.lines[ii];
      break; 
    end;
  end;
end;
于 2016-08-23T13:12:57.380 回答
1

实现这一点的简单方法是遍历备忘录的行并检查它是否以“网关:10.127.”开头。

例如:

for LString in memo.Lines do
  if AnsiStartsText('Gateway:    10.127.', LString) then
    textbox.Caption := LString

您也可以使用正则表达式进行更具体的处理。

于 2016-08-23T12:35:25.063 回答