Back
| Next
Lesson
Manipulating Text
A single piece of text is referred
to as a string
in the wide world of programming. A string consists of 1 or more
characters from the ASCII
table. The ASCII table assigns
an integer (0-255) to each letter, number, and punctuation we see on the screen.
Why? Because the computer only understands numbers, in fact only zeros
and ones - but we won't go there.
Comparisons
The thing about strings are, when you evaluate them - you are evaluating
its underlying ASCII value. For example, we can write:
005
if 'a' < 'd'
Since the ASCII value of "a" is 97 and "d" is 100, the if statement returns true. Not knowing this, you may have written:
006 if $asc('a') < $asc('d')
Which is perfectly ok, just long winded.
007 if 'abc' == 'def'
Line #007 - on the first pass, the ASCII value of "a" is compared with the ASCII value of "d". It does not equal, therefore the if statement is false and "b" and "c" are never evaluated with "e" and "f".
008 if 'ab' < 'af'
Line #008 - on the 1st pass, "a" == "a", but on the 2nd pass, the ASCII value of "b" is compared with the ASCII value of "f". The ASCII value of "b" is less than "f", therefore the if statement is #true.
Operators
The only basic operator is addition (+) or concatenation.
009 s = 'ARRIS'+'cad' /* s='ARRIScad'
010 s = 'Sigma'+'Design'+'International'
Line #010 will return "SigmaDesignInternational" - Don't forget spaces!
Dot Operators
Dot operators perform specialize functions. Character positioning is base1, the first character in the string is position 1.
string = string1 .left. iposition
Returns the left-part of string1, up to and including the (iposition)th character.
016 s = 'ARRIScad'.left.5 /* s='ARRIS'
string = string1 .right. iposition
Returns the (iposition) right-most characters in the string1.
017 s = 'ARRIScad'.right.3 /* s='cad'
string = string1 .from. iposition
Returns all characters to the right of (& including) the (iposition)th character in the string1.
018 s = 'ARRIScad'.from.6 /* s='cad'
string = string1 .pick. iposition
Returns the (iposition)th character in the string1.
019 s = 'ARRIScad'.pick.6 /* s='c'
string = string1 .pos. string2
Returns the beginning position of the first left-most occurrence of string2 in string1.
020 i = 'ARRIScad'.pos.'R' /* i=2
021 i = 'ARRIScad'.pos.'RR' /* i=2
string = string1 .rpos. string2
Returns the beginning position of the first right-most occurrence of string2 in string1.
022 i = 'ARRIScad'.rpos.'R' /* i=3
023 i = 'ARRIScad'.rpos.'RRI' /* i=2
$utilities
There are numerous $utilities that deal with strings. I'll just quickly list them here, leaving the exploration to you and a much later lesson.
Returns:
$acs(s1) ASCII value
$chk(s1) True if s1 is numeric
$chr(i1) Character for i1 (ASCII value)
$len(s1) Number of characters in s1
$str(r1) Converts a number to a numeric string (r1 to s1)
$trim(s1) Trims leading and trailing spaces
$val(s1) Converts a numeric string to a number (s1 to r1)
That's all for now,
Steve
This lesson was brought to you by SCG consulting. All written materials related to these Sigmac lessons are copyrighted by SCG and intended for personal use only. Any commercial or non-commercial reproduction for public use is prohibited without written consent from SCG.
Back
| Next
Lesson