Starting out with a new programming language can be challenging. Learning the functions is one way to go about it. The Perl string lc() function and uc() function are two basic functions that are easy to understand—they convert a string to all lowercase or all uppercase respectively.
以一种新的编程语言开始可能是具有挑战性的。 学习功能是实现它的一种方法。 Perl字符串lc()函数和uc()函数是两个易于理解的基本函数-它们分别将字符串转换为全部小写或全部大写。
Perl String lc() Function
Perl String lc()函数
The Perl lc() function takes a string, makes the entire thing lowercase and then returns the new string. For example:
Perl lc()函数采用字符串,将整个内容转换为小写,然后返回新字符串。 例如:
#!/usr/bin/perl
#!/ usr / bin / perl
$orig_string = "This Test Is Capitalized";
$ orig_string =“此测试为大写”;
$changed_string = lc( $orig_string );
$ changed_string = lc($ orig_string);
print "The Resulting String is: $changed_string\n";
打印“结果字符串是:$ changed_string \ n”;
When executed, this code yields:
执行后,此代码将产生:
The Resulting String is: this test is capitalized
结果字符串为:此测试大写
First, $orig_string is set to a value—in this case, This Test Is Capitalized. Then the lc() function is run on $orig_string. The lc() function takes the entire string $orig_string and converts it to its lowercase equivalent and prints it out as instructed.
首先,将$ orig_string设置为一个值-在这种情况下,此测试为大写。 然后,lc()函数在$ orig_string上运行。 lc()函数采用整个字符串 $ orig_string并将其转换为小写字母,然后按照说明将其打印出来。
Perl String uc()函数 ( Perl String uc() Function )
As you might expect, Perl's uc() function converts a string to all uppercase characters in the same manner. Just substitute uc for lc in the example above, as shown:
如您所料,Perl的uc()函数以相同的方式将字符串转换为所有大写字符。 只需在上面的示例中将uc替换为lc,如下所示:
#!/usr/bin/perl
#!/ usr / bin / perl
$orig_string = "This Test Is Capitalized";
$ orig_string =“此测试为大写”;
$changed_string = uc( $orig_string );
$ changed_string = uc($ orig_string);
print "The Resulting String is: $changed_string\n";
打印“结果字符串是:$ changed_string \ n”;
When executed, this code yields:
执行后,此代码将产生:
The Resulting String is: THIS TEST IS CAPITALIZED
结果字符串是:此测试是大写的
关于Perl ( About Perl )
Perl is a feature-rich programming language that was originally developed for use with text. It is cross-platform and runs on more than 100 platforms. Perl works with HTML and other markup languages, so it is frequently used in web development. Check out the Perl string length function to do more with strings.
Perl是功能丰富的编程语言 ,最初是为与文本一起使用而开发的。 它是跨平台的,可在100多个平台上运行。 Perl与HTML和其他标记语言一起使用,因此在Web开发中经常使用。 查看Perl字符串长度函数可以对字符串进行更多操作。
翻译自: https://www.thoughtco.com/perl-string-lc-function-quick-tutorial-2641188