Strings / Basic Syntax

Crystal Syntax. Enclose strings in cither double quotes (“”) or apostrophes (“)•

•This 1s a string” ‘This Is a string’

•123′

“The word “hello” 1s quoted” “This is not valid’

V

Basic Syntax, You must use double quotes (“”).

Extracting Characters from Strings

Crystal Syntax. Use square brackets [],

He11oC2J //”returns e. the second character 1n the string

Hello t-5] //returns H, the fifth character from the end of the string

Basic Syntax. Use parenthesis ().

Hello (2) ‘Returns e. the second character In the string

Hello (3 to 5) ‘returns log the third through fifth characters In the string

Boolean Values

Both Crystal and Basic syntaxes return true or false. You can use yes and no as substitutes in either syntax.

Date,’ Time, arid Date time

Both Crystal and Basic syntaxes hold date, time, and date time types of field data. Though the datetime type is most versatile, the date type and time type arc more efficient. Datetime literals cannot be split between lines in cither syntax. Create a datetime literal in either syntax by surrounding the date witfc pound signs (##).

11/3/00 2:00 pntf ((September 17. 1992? ‘                              ‘                  ‘      •

023 Aug 1976*

//23_Aug 1976 12i44 put ‘

#9:30 antf

Range Data Types

Both syntaxes accept ranges for all simple data types except Boolean. There are a few differences between the syntaxes when it comes to including the

value in the range. •

Crystal Syntax. There are several options when defining a range, Use any of the following options depending on what values you want returned.

About Author

Leave A Reply