& notation

There are a number of notations in the Xojo language that start with “&”, and I thought it would be handy to post them somewhere as reference.

  • &b - A binary literal, like &b00001111, as an UInt32.
  • &c - A color with RGB + alpha channel values as hex, like &c12ABCDFF, as a Color. (You can leave off the alpha channel, like &c12ABCD.)
  • &h - A hexadecimal literal, like &h12AE, as an UInt32.
  • &o - An octal literal, like &o777, as an UInt32.
  • &u - A Unicode string with the given code point as hex, like &h201C (left double curly quote), as string.

You’d use these as you would any constant. Just type them without quotes in places where you might otherwise use a number, color, or string. For example, these both do exactly the same thing:

n = &b11111111
n = 255

So do these:

s = &u61
s = "a"

You can also use these within a string to convert that string to a number with Val. For example, if you have the string “0A”, you can use this code to convert it to a number:

s = "0A"
n = Val( "&h" + s )
// n = 10

Hope someone finds this useful. Personally, I didn’t know (or remember) about the “&u” notation until Norman posted about it today in another conversation.

&u is the least known but extremely useful. In 2014r1 it’ll be even more useful because 2014r1 supports constants whose value is a constant expression. So, for example:

Const CRLF = &u0C + &u0A

Typo correction.

Const CRLF = &u0D + &u0A

And cool.

Like here http://documentation.xojo.com/index.php/Category:Language_Literals ?

[quote=66646:@Joe Ranieri]&u is the least known but extremely useful. In 2014r1 it’ll be even more useful because 2014r1 supports constants whose value is a constant expression. So, for example:

Const CRLF = &u0C + &u0A

Nice. Perhaps it’s least-known because it’s the most recent addition? :slight_smile:

Handy when you want a particular symbol & can just use the code point