-2
我有一個字符串刪除數據
my $string = $14.275; ## where i need to remove the $
我已經通過使用下面的代碼嘗試的第一部分中的$
$y = substr($string , 1, index($string));
輸出應該是14.275
我有一個字符串刪除數據
my $string = $14.275; ## where i need to remove the $
我已經通過使用下面的代碼嘗試的第一部分中的$
$y = substr($string , 1, index($string));
輸出應該是14.275
首先引用串價值和寫這樣的代碼:
#!/usr/bin/perl
use warnings;
use strict;
my $string = '$14.275';
$string =~ s/^\$//;
print "$string\n";
輸出:
14.275
您需要在初始化時引用引號。 – 2015-04-03 19:12:01
如果美元符號總是在那裏,'substr($ string,1)'就足夠了。更好的轉換可能是'$ string =〜s/^ \ $ //;' – 2015-04-03 19:13:26
謝謝你的工作.. – user3045098 2015-04-03 19:40:02