使用Perl Win32 :: GUI从Text Area控件获取修剪文本

时间:2011-12-07 09:48:26

标签: perl

如何从TextArea控件中检索剪裁文本(LTRIM和RTRIM)。 TextArea控件已通过Win32 :: GUI模块创建。

use strict;
use Win32;
use Win32::GUI;


my $DOS = Win32::GUI::GetPerlWindow();
Win32::GUI::Hide($DOS);

my $main_window=Win32::GUI::Window->new(
        -name => 'main_window',
        -text => 'main_window_Test',
        -left => 375,
        -top  => 200,
        -width =>510,#370,
        -height =>220,
        -background => [190,190,190],
        -dialogui   => 1,
        -maximizebox => 0,
  );

my $Entry_Path=$main_window->AddTextfield(
        -name => 'entrypath',
        -pos => [220,66],
        -size => [180,23],
        -align => 'left',
        -foreground => [],
        -tabstop => 1,
  );


my $get_trim_Button=$main_window->AddButton(                     
        -text => 'Create Trimmed texts',
        -name =>  'ncxcreate',
        -size => [110,20],
        -align=>center,
        -pos  =>  [255,150],
        -background =>  [190,190,190],
        -foreground => [],
        -tabstop => 1,
        -disabled=>1
  );

$main_window->Show();
Win32::GUI::Dialog();

sub ncxcreate_Click{
 my $text_received=$Entry_Path->Text;
}

在上面的代码中,我需要检索$ text_received标量中的修剪文本值(前导空格和尾随空格删除文本)。

1 个答案:

答案 0 :(得分:1)

所以你正在寻找修剪功能?

sub trim { ( my $s = $_[0] ) =~ s/^\s+|\s+$//g; $s }

sub trim { $_[0] =~ s/^\s+|\s+$/gr }  # 5.14+

使用/ m也可以从每一行中删除前导和尾随空格。

sub trim_multi { ( my $s = $_[0] ) =~ s/^\s+|\s+$//mg; $s }

sub trim_multi { $_[0] =~ s/^\s+|\s+$/mgr }  # 5.14+