2011-05-10 40 views
0

我有一些文字:我怎样才能在某些文字中仅使用某些单词?

一段文字是一堆行盒。在“左”,“右”和“中”的情况下,该属性指定每个线框内的内联等级框如何与线框的左右侧对齐;对齐不是关于视口。在'证明'的情况下,该属性指定如果可能的话,通过展开或缩小内联框的内容,使内联层框与线框的两侧齐平,否则按照初始值对齐。 (另见'字母间距'和'字间距'。)

带有“th”的文本中的所有单词都应该用大写字母(使用函数uc)编写。

这里是我的代码

@tykeldatud=split(/ /, $string); 
[email protected]; 
for ($i=1;$i<=$j;$i++) { 
    ... 

我应该写未来?

回答

2
use warnings; 
use strict; 

my $string = <<EOF; 
A block of text is a stack of line boxes. In the case of 'left', 
'right' and 'center', this property specifies how the inline-level 
boxes within each line box align with respect to the line box's left 
and right sides; alignment is not with respect to the viewport. In 
the case of 'justify', this property specifies that the inline-level 
boxes are to be made flush with both sides of the line box if 
possible, by expanding or contracting the contents of inline boxes, 
else aligned as for the initial value. (See also 'letter-spacing' and 
'word-spacing'.) 
EOF 

my $string2; 
for (split//, $string) { 
    $_ = uc if /th/i; 
    $string2 .= "$_ "; 
} 
print "$string2\n"; 
3

这只是一个替代。

 
use strict; 
use warnings; 

my $string = <<EOF; 
A block of text is a stack of line boxes. In the case of 'left', 
'right' and 'center', this property specifies how the inline-level 
boxes within each line box align with respect to the line box's left 
and right sides; alignment is not with respect to the viewport. In 
the case of 'justify', this property specifies that the inline-level 
boxes are to be made flush with both sides of the line box if 
possible, by expanding or contracting the contents of inline boxes, 
else aligned as for the initial value. (See also 'letter-spacing' and 
'word-spacing'.) 
EOF 

$string =~ s/\b(\S*th\S*)\b/uc $1/ieg; 
print $string; 
+2

为规范陈述 “与 '日' 的所有单词”,您的搜索模式也许应该是'\ B(\ S *日\ S *)' – Axeman 2011-05-10 18:33:39

+1

好一点。谢谢。 – 2011-05-10 18:44:55

相关问题