Getting Started Documentation Glish Learn More Programming Contact Us
Version 1.9 Build 1556
News FAQ
Search Home


next up previous
Next: Printing Up: NOTE 195 Getting Started with Glish for AIPS++ Previous: Records and Attributes

Strings

There are two types of string constants in glish. Single quoted strings are treated as a single entity and are most useful in print statements where some control of placement of characters on the screen is important. Double quoted strings are treated as arrays of strings with white space separating the array members. The output of 'field_names()' in the example above is an instance of a string array. The difference is best illustrated with some examples.

- s1 := 'This is a single quoted      string'
- s2 := "This is a double quoted      string"
- s1
This is a single quoted      string 
- s2
This is a double quoted string 
- s1[1]
This is a single quoted      string 
- s2[1]
This 
- s1[2]
<fail>: index (= 2) out of range, array length = 1 
- s2[2]
is

Notice that all white spaces have been reduced to single spaces when the double quoted string array is printed.

String handling is fairly primitive in glish. There are no string operators, except possibly for the cautious use of the comparison operators.

- twenty := '20'
- three := '3'
- twenty < three
T

If one of the variables, twenty or three, had not been a string, an error would have been reported. When in doubt, use the is_string() test first.

There are a few string manipulation functions, including paste(), spaste(), and split(). Paste() and spaste() act like print statements except that the resulting string is returned as a single string instead of being printed.

- r := 53.6
- sx := paste('R =', r)
- sx
R = 53.6

The paste() function can take a named argument, sep, to change the separator character(s) from the space default.

- paste('R', r, sep=' = ')
R = 53.6

The function spaste() is the same as paste() with no separator. The string function split() simply turns a single string into a string array or breaks a string array differently. It takes two arguments, the string to be split and a list of characters to be used as separators. The default separator is a space.

- str1 := 'This is a single quoted string'
- str2 := "This is a double quoted string"
- sx := split(str1)
- sx[1]
This
- sx := split(str2, "u")
- sx
This is a do ble q oted string
- sx[3]
oted string


next up previous
Next: Printing Up: NOTE 195 Getting Started with Glish for AIPS++ Previous: Records and Attributes
Please send questions or comments about AIPS++ to aips2-request@nrao.edu.
Copyright © 1995-2000 Associated Universities Inc., Washington, D.C.

Return to AIPS++ Home Page
2006-10-15