2011-05-10 121 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

相關問題