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

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-25 21:47:28

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!