Reputation: 1
In my below script, the str_replace(rtrim(c_manager),'''','_')
doesn't seem to work.
I want to replace single quotes with underscores for my arguments. For example:
Input: `S'achin`
Result: `S_achin`
$sql = 'select rtrim(f_admin_disabled),'."\n".
' convert(varchar,t_password,101),'."\n".
' rtrim(c_email),'."\n".
' str_replace(rtrim(c_manager),'''','_'),'."\n".
' rtrim(c_mgr_email)'."\n".
' from tuserprofile'."\n".
' where ic_user1 = '."'$user_id'"."\n";
Upvotes: 0
Views: 4997
Reputation: 650
to replace a character in string
$string=~s/'/_/g;
Syntax
$string=~s/<string>/<replace_string>/g;
Upvotes: 2
Reputation: 98398
If you want to have single quotes in a single quoted string to produce str_replace(rtrim(c_manager),'''','_'),
you need to either escape them:
' str_replace(rtrim(c_manager),\'\'\'\',\'_\'),'
or use a different delimiter:
q! str_replace(rtrim(c_manager),'''','_'),!
Upvotes: 3
Reputation: 3153
Use this subroutine.
sub str_replace {
my ($s) = @_;
$s =~ s/'/_/g;
return $s;
}
Upvotes: 0