[英]Substitute, replace string with perl
I have string like this: 我有这样的字符串:
$string= "only this I need"
. $string= "only this I need"
。
I am new in perl, and I tried to translate a PL/SQL code in perl. 我是perl的新手,我尝试在perl中转换PL / SQL代码。
My goal is to replace "
with a blank space, finally it should look like this: 我的目标是用空格替换
"
,最后应如下所示:
$string = only this I need
In PL/SQL I use this, and is working very well: 在PL / SQL中,我使用了它,并且运行良好:
REGEXP_REPLACE(string,'"','');
In perl I tried this, but is not working: $string=~s/"/'';
receiving an error. 在perl中,我尝试了此操作,但不起作用:
$string=~s/"/'';
收到错误。
Please, help me, tell me what I need to read to do my job properly? 请帮帮我,告诉我正确阅读我的书需要做什么?
Try this it should work: 试试这个,它应该工作:
use strict;
use warnings;
my $string= '"only this I need"';
print "$string \n"; #prints "only this I need"
$string =~ s/"/ /g;
print "$string \n"; #prints only this I need
This is a way to remove quotes from string: 这是一种删除字符串中引号的方法:
my $string= '"only this I need"';
$string =~ m/"([^"]*)"/;
print "$1\n";
In case if you know the first and last character is quotes, you can do this without using regex
, just use substr
: 如果您知道第一个和最后一个字符是引号,则可以在不使用
regex
情况下执行此操作,只需使用substr
:
my $string= '"only this I need"';
$string = substr $string, 1, -1;
print "$string\n";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.