如何捕获备忘录文本以编辑Delphi

时间:2016-08-23 12:19:49

标签: delphi wildcard delphi-7 tmemo

我想将备忘录中填充的动态网关IP捕获到文本框中。 如何使用通配符或捕获以" Gateway: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)); 

2 个答案:

答案 0 :(得分:3)

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

ToDoController

答案 1 :(得分:1)

实现这一目标的简单方法是迭代备忘录的行并检查它是否以“Gateway:10.127”开头。

例如:

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

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