Basics-Constants.xml 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
  4. <sect1 id="Constants">
  5. <title>Constants</title>
  6. <sect2 id="Const_String">
  7. <title>String</title>
  8. <para>All string literals must be contained within single quotation marks
  9. ( ' ' ). All ECL code is UTF-8 encoded, which means that all strings are
  10. also UTF-8 encoded, whether Unicode or non-Unicode strings. Therefore, you
  11. must use a UTF-8<indexterm>
  12. <primary>UTF-8</primary>
  13. </indexterm> editor (such as the ECL IDE <indexterm>
  14. <primary>ECL IDE</primary>
  15. </indexterm> program).</para>
  16. <para>To include the single quote character (apostrophe) in a constant
  17. string, prepend a backslash (\). To include the backslash character (\) in
  18. a constant string, use two backslashes (\\) together.</para>
  19. <programlisting>STRING20 MyString2 := 'Fred\'s Place';
  20. //evaluated as: "Fred's Place"
  21. STRING20 MyString3 := 'Fred\\Ginger\'s Place';
  22. //evaluated as: "Fred\Ginger's Place"</programlisting>
  23. <para>Other available escape characters are:</para>
  24. <para><informaltable colsep="1" frame="all" rowsep="1">
  25. <tgroup cols="2">
  26. <colspec colwidth="85.75pt" />
  27. <colspec />
  28. <tbody>
  29. <row>
  30. <entry><emphasis role="code">\t</emphasis></entry>
  31. <entry>tab</entry>
  32. </row>
  33. <row>
  34. <entry><emphasis role="code">\n</emphasis></entry>
  35. <entry>new line</entry>
  36. </row>
  37. <row>
  38. <entry><emphasis role="code">\r</emphasis></entry>
  39. <entry>carriage return</entry>
  40. </row>
  41. <row>
  42. <entry><emphasis role="code">\nnn</emphasis></entry>
  43. <entry>3 octal digits (for any other character)</entry>
  44. </row>
  45. <row>
  46. <entry><emphasis role="code">\uhhhh</emphasis></entry>
  47. <entry>lowercase "u" followed by 4 hexadecimal digits (for any
  48. other UNICODE-only character)</entry>
  49. </row>
  50. </tbody>
  51. </tgroup>
  52. </informaltable></para>
  53. <programlisting>MyString1 := 'abcd';
  54. MyString2 := U'abcd\353'; // becomes 'abcdë'
  55. </programlisting>
  56. <para><emphasis role="bold">Hexadecimal<indexterm>
  57. <primary>Hexadecimal</primary>
  58. </indexterm> string constants<indexterm>
  59. <primary>string constants</primary>
  60. </indexterm> </emphasis>must begin with a leading “x” character. Only
  61. valid hexadecimal values (0-9, A-F) may be in the character string and
  62. there must be an even number of characters.</para>
  63. <programlisting>DATA2 MyHexString := x'0D0A'; // a 2-byte hexadecimal string</programlisting>
  64. <para><emphasis role="bold">Data string<indexterm>
  65. <primary>Data string</primary>
  66. </indexterm> constants<indexterm>
  67. <primary>constants</primary>
  68. </indexterm> </emphasis>must begin with a leading “D” character. This is
  69. directly equivalent to casting the string constant to DATA.</para>
  70. <programlisting>MyDataString := D'abcd'; // same as: (DATA)'abcd'</programlisting>
  71. <para><emphasis role="bold">Unicode string<indexterm>
  72. <primary>Unicode string</primary>
  73. </indexterm> constants </emphasis>must begin with a leading “U”
  74. character. Characters between the quotes are utf8-encoded and the type of
  75. the constant is UNICODE.</para>
  76. <programlisting>MyUnicodeString1 := U'abcd'; // same as: (UNICODE)'abcd'
  77. MyUnicodeString2 := U'abcd\353'; // becomes 'abcdë'
  78. MyUnicodeString3 := U'abcd\u00EB'; // becomes 'abcdë'</programlisting>
  79. <para><emphasis role="bold">VARSTRING string constants<indexterm>
  80. <primary>VARSTRING string constants</primary>
  81. </indexterm> </emphasis>must begin with a leading “V” character. The
  82. terminating null byte is implied and type of the constant is
  83. VARSTRING.</para>
  84. <programlisting>MyVarString := V'abcd'; // same as: (VARSTRING)'abcd'</programlisting>
  85. <para><emphasis role="bold">QSTRING string constants<indexterm>
  86. <primary>QSTRING string constants</primary>
  87. </indexterm> </emphasis>must begin with a leading “Q” character. The
  88. terminating null byte is implied and type of the constant is
  89. VARSTRING.</para>
  90. <programlisting>MyQString := Q'ABCD'; // same as: (QSTRING)'ABCD'</programlisting>
  91. </sect2>
  92. <sect2 id="Numeric">
  93. <title>Numeric</title>
  94. <para>Numeric constants containing a decimal portion are treated as REAL
  95. values (scientific notation is allowed) and those without are treated as
  96. INTEGER<indexterm>
  97. <primary>INTEGER</primary>
  98. </indexterm> (see <emphasis role="bold">Value Types</emphasis>). Integer
  99. constants may be decimal, hexadecimal, or binary values.
  100. Hexadecimal<indexterm>
  101. <primary>Hexadecimal</primary>
  102. </indexterm> values are specified with either a leading “0x” or a
  103. trailing “x” character. Binary values<indexterm>
  104. <primary>Binary values</primary>
  105. </indexterm> are specified with either a leading “0b” or a trailing “b”
  106. character.</para>
  107. <programlisting>MyInt1 := 10; // value of MyInt1 is the INTEGER value 10
  108. MyInt2 := 0x0A; // value of MyInt2 is the INTEGER value 10
  109. MyInt3 := 0Ax; // value of MyInt3 is the INTEGER value 10
  110. MyInt4 := 0b1010; // value of MyInt4 is the INTEGER value 10
  111. MyInt5 := 1010b; // value of MyInt5 is the INTEGER value 10
  112. MyReal1 := 10.0; // value of MyReal1 is the REAL value 10.0
  113. MyReal2 := 1.0e1; // value of MyReal2 is the REAL value 10.0
  114. </programlisting>
  115. </sect2>
  116. </sect1>