02.05.2013 Views

Description - Mks.com

Description - Mks.com

Description - Mks.com

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

If expression is a vector, the value is the number of elements in the vector. If expression is a string,<br />

the value is the number of characters in the string; otherwise, the value is 0.<br />

String/Vector Operators<br />

The operator | concatenates strings or vectors. The form is<br />

expression1 | expression2<br />

where expression1 must be a string or vector. If expression1 is a string, the second argument is<br />

converted to a string and the two strings are concatenated for the result. For example, in<br />

X = "hello";<br />

X = X | " good" | "bye";<br />

the variable X is assigned the value<br />

"hello goodbye"<br />

You can use the shorthand notation |= to append to the end of an existing string, as in<br />

x = "hello";<br />

x |= " good" | "bye";<br />

which has the same result.<br />

If the first argument of the | operator is a vector, the second argument is added as a new<br />

<strong>com</strong>ponent to the vector. In this way, you can assign values to a vector incrementally. You can use<br />

the |= operator as a shorthand assignment. For example:<br />

x = {} # ensure x is a vector<br />

x |= 1; # x is now { 1 }<br />

x |= "so"; # x is now { 1, "so" }<br />

x |= 2 | 3; # x is now { 1, "so", "23" }<br />

# Remember, the '|' is applied to '2' and '3',<br />

# forming a string, that is then added<br />

x |= { 4, 5 }; # x is now { 1, "so", "23", 4, 5 }<br />

Assignments<br />

There are several assignment expressions.<br />

name = expression ;<br />

318 of 457

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!