Search code examples
powerbuilder

In Power Builder trying to replace a escape character with ~ sign


I am new to the power builder I am trying to use replace function. I needed to replace a aposthope(') in string with ~' but it is giving me an error "Bad argument list for function: replace" .

Signature = "Gagandeep S'ingh"

Signature = Replace (Signature , "'", "~'")

Any help here please.


Solution

  • Tilde is a modifier character in PowerBuilder. The first function it has is to represent special characters, so you have ~r, ~n, ~t for carriage return, newline, and tab. The second function is an escape that removes any special meaning of the following character. This allows you to write things like "~"" to make a string that contains a quote character. In that case it's better to write '"', but if you've already done that and want a single quote you have to escape it. Creating expressions for the DataWindow requires additional levels of escaping that I won't get into here. What's happening when you write "~'" is that the tilde tells PowerBuilder to treat the single quote as an ordinary character. It would do that anyway in this case since it's not inside a single-quoted string. That's why you're replacing the ' with another '. If you want ~' you have to write "~~'". The first tilde tells PowerBuilder to treat the following tilde as a regular character, and you end up with ~'. PowerBuilder help lists ~~ as the special character for tilde, and ~' and ~" for the quote characters but when you work with more than one level of escaping you're better off treating it as an escape and working left to right.