博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Perl trim function to strip whitespace from a string
阅读量:4221 次
发布时间:2019-05-26

本文共 1078 字,大约阅读时间需要 3 分钟。

Perl trim function to strip whitespace from a string

Perl does not have a built-in trim function. Use the subroutine below to trim whitespace (spaces and tabs) from the beginning and end of a string in Perl. This function is directly based on the Perl FAQ entry, How do I strip blank space from the beginning/end of a string?. The ltrim and rtrim functions can trim leading or trailing whitespace.

#!/usr/bin/perl# Declare the subroutinessub trim($);sub ltrim($);sub rtrim($);# Create a test stringmy $string = "  /t  Hello world!   ";# Here is how to output the trimmed text "Hello world!"print trim($string)."/n";print ltrim($string)."/n";print rtrim($string)."/n";# Perl trim function to remove whitespace from the start and end of the stringsub trim($){	my $string = shift;	$string =~ s/^/s+//;	$string =~ s//s+$//;	return $string;}# Left trim function to remove leading whitespacesub ltrim($){	my $string = shift;	$string =~ s/^/s+//;	return $string;}# Right trim function to remove trailing whitespacesub rtrim($){	my $string = shift;	$string =~ s//s+$//;	return $string;}

转载地址:http://riqmi.baihongyu.com/

你可能感兴趣的文章
nginx(二) nginx编译安装 及 配置WEB服务
查看>>
nginx(三) nginx配置:反向代理 负载均衡 后端健康检查 缓存
查看>>
nginx(四) nginx+keepalived 实现主备+双主热备模型的高可用负载均衡代理服务
查看>>
jQuery核心--多库共存
查看>>
QTP Tutorial #23 – QTP Smart Object Identification, Sync Point, and Test Result Analysis
查看>>
第一章漫话自动化测试
查看>>
第二章:Selenium IDE应用实践
查看>>
第三章:Python基础
查看>>
正则表达式
查看>>
第五章 自动化测试模型
查看>>
Linux命令行与shell编程第3章基本的shell
查看>>
Linux命令行与shell编程第4章 更多的bash shell命令
查看>>
4 51 单片机最小系统
查看>>
6 51点亮第一个LED
查看>>
8 51 LED流水灯
查看>>
Multisim 14.0 搭建并仿真51单片机最小系统
查看>>
51 中断系统 外部中断0 外部中断1
查看>>
51 单片机 时间/计数器中断
查看>>
腾讯云本地还原mysql物理冷备
查看>>
算法图解 第1章 算法简介
查看>>