User Tools

Site Tools


strings

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
strings [2018/02/14 05:13] wolfgangriedmannstrings [2018/10/06 05:09] (current) wolfgangriedmann
Line 3: Line 3:
 A string in X# is delimited by the double quotation mark: A string in X# is delimited by the double quotation mark:
  
-<code>cString := "this is a string"</code>+<code visualfoxpro>cString := "this is a string"</code>
  
 This is valid for the VO, Vulcan and Code dialects. In the VO dialect a string can also be delimited by the single quotation mark: This is valid for the VO, Vulcan and Code dialects. In the VO dialect a string can also be delimited by the single quotation mark:
-<code>cString := 'this is a string'</code>+<code visualfoxpro>cString := 'this is a string'</code>
  
 This is to make X# compatible to VO code. This is to make X# compatible to VO code.
  
 If you need to use special characters or double quotation mark in your string, the enhanced string does what you need: If you need to use special characters or double quotation mark in your string, the enhanced string does what you need:
-<code>cString := e"this is a \"string\"."</code>+<code visualfoxpro>cString := e"this is a \"string\"."</code>
  
 and of course you can also embed other control characters in your string: and of course you can also embed other control characters in your string:
-<code>cString := e"this is a multiline\nstring with another\nline"</code>+<code visualfoxpro>cString := e"this is a multiline\nstring with another\nline"</code>
  
 But you can do even more with interpolated strings: But you can do even more with interpolated strings:
-<code>local cMyVar := "Hi" as string+<code visualfoxpro>local cMyVar := "Hi" as string
  
 cString := i"{cMyVar} guys"</code> cString := i"{cMyVar} guys"</code>
  
 Of course you can use both at the same time: Of course you can use both at the same time:
-<code>cString := ei"this is a \"string\". that references {cLocalVar}"</code>+<code visualfoxpro>cString := ei"this is a \"string\". that references {cVariableName}"</code> 
 + 
 +As variable, not only a string variable can be used, but every type of object, and under the houd the '':ToString()'' method is called: 
 + 
 +<code visualfoxpro>local oPerson as Person 
 + 
 +cString := i"This is {oPerson}"</code> 
 + 
 +And if you wish, you can also use formatting expressions: 
 + 
 +<code visualfoxpro>local nValue as decimal 
 + 
 +nValue := 123.45m  
 +cString := i"nValue: {nValue:######.0000}" // nValue: 123,4500 
 +cString := i"nValue: {nValue:F6}" // nValue: 123,450000</code>  
 + 
 +In this case (as in the use with ToString()), if you need to embed the parentheses ''{'' and ''}'' in your string, they need to be doubled as in this sample: 
 +<code visualfoxpro>cConnection := i"Driver={{Microsoft access Driver (*.mdb)}};Dbq={cDatabaseFile};Uid=Admin;Pwd=;"</code>
  
 And only in the VO dialect, you need to prefix a char with the ''c'' prefix: And only in the VO dialect, you need to prefix a char with the ''c'' prefix:
-<code>cChar := c'a'</code>+<code visualfoxpro>cChar := c'a'</code> 
 + 
 +Please note that there is a major difference between C# and X#: in C# all strings are enhanced, and to make them normal, you must prefix them with the ''@'' character. 
 +In X# all strings are normal, and to be enhanced, they need the ''e'' prefix.
  
  
strings.1518585186.txt.gz · Last modified: 2018/02/14 05:13 by wolfgangriedmann