繁体   English   中英

替换,用perl替换字符串

[英]Substitute, replace string with perl

我有这样的字符串:

$string= "only this I need"

我是perl的新手,我尝试在perl中转换PL / SQL代码。
我的目标是用空格替换" ,最后应如下所示:

$string = only this I need

在PL / SQL中,我使用了它,并且运行良好:

REGEXP_REPLACE(string,'"','');

在perl中,我尝试了此操作,但不起作用: $string=~s/"/'';收到错误。

请帮帮我,告诉我正确阅读我的书需要做什么?

试试这个,它应该工作:

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

这是一种删除字符串中引号的方法:

my $string= '"only this I need"';
$string =~ m/"([^"]*)"/;
print "$1\n";

如果您知道第一个和最后一个字符是引号,则可以在不使用regex情况下执行此操作,只需使用substr

my $string= '"only this I need"';
$string = substr $string, 1, -1;
print "$string\n";

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM