字符串处理如何把字符串中指定的字符串以后的全部删除
字符串处理如何把字符串中指定的字符串以后的全部删除
E:/Inetpub/wwwroot/cgi-bin/admin
去除/cgi-bin和以后的所有字符串
[解决办法]
Perl:
my $s = 'E:/Inetpub/wwwroot/cgi-bin/admin ';
$s =~ s/cgi-bin.*$//;
print $s;
Python:
s = r 'E:/Inetpub/wwwroot/cgi-bin/admin '
if 'cgi-bin ' in s: s = s[:s.index( 'cgi-bin ')]
print s
[解决办法]
Perl
my $s = 'E:/Inetpub/wwwroot/cgi-bin/admin ';
$s = $` if $s =~ /\/cgi-bin/;
Python
s = r 'E:/Inetpub/wwwroot/cgi-bin/admin '
idx = s.find(r '/cgi-bin ')
if idx > = 0: s = s[:idx]