![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
As you learned in Segment 462, you denote a particular
character by prefixing that character with a $
prefix, thus
distinguishing the character from, say, a variable name. For example, you
denote the character V by writing $V
.
If you want to see whether you have extracted a particular character, you
compare what you have extracted with that character. Then, if you wish,
you can build an ifTrue:
expression on that comparison, as in the
following example, which prints only those strings for which the first
character is V:
Food method definition class eatOnlyVegetables: aFile |inputStream string | inputStream := File pathName: aFile. [inputStream atEnd] whileFalse: [(string := inputStream nextLine) notEmpty ifTrue: [(string at: 1) = $V ifTrue: [Transcript show: string printString; cr]]]. inputStream close Workspace Food eatOnlyVegetables: 'c:\test\foods.dta' Transcript 'V Broccoli 3 16 9 0.5c ' 'V Carrots 1 33 4 0.5c good for rabbits' 'V Corn 1 23 6 0.5c' 'V Cabbage 2 14 3 0.5c'