0

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";

3 Answers 3

3

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),'''','_'),!
Sign up to request clarification or add additional context in comments.

Comments

2

to replace a character in string

$string=~s/'/_/g;

Syntax

$string=~s/<string>/<replace_string>/g;

2 Comments

There're no needs to escape the quote and to have the i modifier.
how will use on the above select statement
0

Use this subroutine.

sub str_replace {
  my ($s) = @_;

  $s =~ s/'/_/g;

  return $s;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.