Significance of "~" symbol

abhishek.shah

New Member
Actually we are going through our codes for removal of hard-coded strings replacing them by our field variables.
PUT STREAM mail UNFORMATTED "objMessage.Configuration.Fields.Item _ " skip.
PUT STREAM mail UNFORMATTED "(~"http://schemas.microsoft.com/cdo/configuration/sendusername~") = ~"mis@tspl.com~" " SKIP.

PUT STREAM mail UNFORMATTED "objMessage.Configuration.Fields.Item _ " skip.
PUT STREAM mail UNFORMATTED "(~"http://schemas.microsoft.com/cdo/configuration/sendpassword~") = ~"abcdtestpassword~" " SKIP.

Now I need to put up a function GetCodeMasterDesc("param1","param2") which returns password in string value in place of hard-coded ~"abcdtestpassword~".

Would appreciate if anyone can please help me with this. Also enlighten me with the "~" symbol used.
Thanks in advance.
 

Rob Fitzpatrick

ProgressTalk.com Sponsor
You will find a reference to it in the OpenEdge help, listed under "~ (tilde)" (sub-section: Special character) in the index (at the top). It says:

~ Special character
The tilde (~) is an escape character that causes the AVM to read the following character literally. A tilde followed by three octal digits represents a single character. Use it as a lead-in to enter the special characters shown in Table 2. In a procedure, a tilde followed by something other than the items in Table 2 is ignored. For example, "~abc" is treated as "abc". (This may not work as expected when passing parameters to an include file.) The items in Table 2 are case sensitive.
 

RealHeavyDude

Well-Known Member
Outside of hard coded strings like "~some string~" the tilde symbol (just like the backslash on *nix) is used to concatenate code lines into one statement. For example pre-processor definitions may not be split across multiple lines unless you use the tilde symbol to tell the compiler that the code, although split across multiple lines, is a single statement.

In the past, by that I mean the good ole CHUI procedure editor days, the editor automatically did split lines of code that exceeded the 80 character limit into multiple lines, inserting a tilde symbol.

Heavy Regards, RealHeavyDude.
 

Stefan

Well-Known Member
Actually we are going through our codes for removal of hard-coded strings replacing them by our field variables.
PUT STREAM mail UNFORMATTED "objMessage.Configuration.Fields.Item _ " skip.
PUT STREAM mail UNFORMATTED "(~"http://schemas.microsoft.com/cdo/configuration/sendusername~") = ~"mis@tspl.com~" " SKIP.

In the above cases you do not need to be using the tilde. You should probably be using the QUOTER function:

Code:
DEF VAR curl AS CHAR INIT "http://schemas.microsoft.com/cdo/configuration/sendusername".
DEF VAR cpass AS CHAR INIT "mis@tspl.com".
PUT STREAM mail UNFORMATTED SUBSTITUTE( "&1 = &2", QUOTER( curl ), QUOTER( cpass ) ) SKIP.

Alternatively you can also use single quotes versus double quotes, but you are then relying on your input not having single quotes:

Code:
[COLOR=#333333]PUT STREAM mail UNFORMATTED '"http://schemas.microsoft.com/cdo/configuration/sendusername") = "mis@tspl.com" ' SKIP.
[/COLOR]


So the first approach (quoter) is best.
 

abhishek.shah

New Member
Thank you all for the replies.
But I need to call a simple function in place of the string "abcdtestpassword". The function returns the string "abcdtestpassword" which it fetched from a database table. The problem has arise since the whole statement is within ~(tilde).
I'm looking for something like :
PUT STREAM mail UNFORMATTED "(~"http://schemas.microsoft.com/cdo/configuration/sendpassword~") = ~"" + func_CodeMasterDesc("str_code_name","str_email_id") + "~" " SKIP.

Can this work?
 

abhishek.shah

New Member
Problem solved!!
I used
PUT STREAM mail UNFORMATTED "(~"http://schemas.microsoft.com/cdo/configuration/sendpassword~") = " + "~"" + GetCodeMasterDesc("XX_EMAIL_ACK","mis@tspl.com") + "~"" SKIP.

Thanks everyone for the prompt replies.
 

Stefan

Well-Known Member
Thank you all for the replies.
But I need to call a simple function in place of the string "abcdtestpassword". The function returns the string "abcdtestpassword" which it fetched from a database table. The problem has arise since the whole statement is within ~(tilde).

So remove the problem (the tildes).

I'm looking for something like :
PUT STREAM mail UNFORMATTED "(~"http://schemas.microsoft.com/cdo/configuration/sendpassword~") = ~"" + func_CodeMasterDesc("str_code_name","str_email_id") + "~" " SKIP.

Can this work?

As stated before use a combination of substitute and quoter, no need to mess around with tildes. The tildes will also NOT catch any quotes returned by your function (allowing injection), whereas QUOTER will.

Code:
PUT STREAM mail UNFORMATTED SUBSTITUTE( "&1 = &2", QUOTER( "http://schemas.microsoft.com/cdo/configuration/sendpassword" ), QUOTER( func_CodeMasterDesc("str_code_name","str_email_id") ) SKIP.

Note that QUOTER is not completely safe, using a tilde with an octal value ~042 allows a double quote to be inserted (search for webspeed injection on psdn).
 
Top