加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

如何在perl中截断一个特定长度的字符串?

发布时间:2020-12-15 21:19:55 所属栏目:大数据 来源:网络整理
导读:我只是不能在Perl中找到“truncate a string to a specific length”。 有没有内置的方式? 更新: 输入:$ str =“abcd”; 输出(截断3个字符):$ str是abc 解决方法 你想使用substr()函数。 $shortened = substr( $long,50 ); # 50 characters long,startin
我只是不能在Perl中找到“truncate a string to a specific length”。
有没有内置的方式?

更新:

输入:$ str =“abcd”;

输出(截断3个字符):$ str是abc

解决方法

你想使用substr()函数。
$shortened = substr( $long,50 ); # 50 characters long,starting at the beginning.

更多,请使用perldoc

perldoc -f substr

在你的情况下,它将是:

$str = 'abcd';
$short = substr( $str,3 );

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读