问题
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.
回答1:
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.
回答2:
From the PowerBuilder help:
Replace PowerScript function
Replaces a portion of one string with another.
Syntax: Replace ( string1, start, n, string2 )
You need to designate how many characters you wish to replace. If you want to insert string2 into string1 you use 0.
So with your example you should try something like:
IF POS(Signature, "'") > 0 THEN
Signature = Replace (Signature, POS(Signature, "'"), 1, "~'")
END IF
回答3:
Here is my current code:
llSigCount = ldsSig.Retrieve(iuQstr.isPtID, iuQstr.ilPtVisitID, iuQstr.ilQstrID, AUTH_EVENT_TYPE)
IF llSigCount > 0 THEN
lsSignature = ldsSig.GetItemString(1, "cf_name_date")
IF POS(Signature, "'") > 0 THEN
Signature = Replace (Signature, POS(Signature, "'"), 1, "~'")
END IF
dw_edit.Modify("auth_signature_t.Text='" + lsSignature + "'")
END IF
来源:https://stackoverflow.com/questions/44373996/in-power-builder-trying-to-replace-a-escape-character-with-sign