| 1 |
|
|---|
| 2 | rem -----------------------------------------------------------------------------------------------
|
|---|
| 3 | echo `@word[] and @words[] are smart enough to recognize a quoted string as one word--`
|
|---|
| 4 | set string=`one two "three four" five six`
|
|---|
| 5 | gosub ShowIt
|
|---|
| 6 | echo `But if the quoted string is the first word, @words[] returns the wrong count.`
|
|---|
| 7 | echo `Explicitly setting the word separator with '@words[" ",%string]'`
|
|---|
| 8 | echo `seems to work around the problem--`
|
|---|
| 9 | set string=`"one" two three four five six`
|
|---|
| 10 | gosub ShowIt
|
|---|
| 11 | echo `And it gets stranger. Just changing the capitalization changes the`
|
|---|
| 12 | echo `word count`
|
|---|
| 13 | set string=`"ONE" two three four five six`
|
|---|
| 14 | gosub ShowIt
|
|---|
| 15 | set string=`"One" two three four five six`
|
|---|
| 16 | gosub ShowIt
|
|---|
| 17 | echo `or try using numbers for words--`
|
|---|
| 18 | set string=`"one" 2 three four five six`
|
|---|
| 19 | gosub ShowIt
|
|---|
| 20 | set string=`"one" 2 3 4 5 6`
|
|---|
| 21 | gosub ShowIt
|
|---|
| 22 | echo `The @word[] function correctly identifies words in all cases,`
|
|---|
| 23 | echo `without needing to specify a word separator`
|
|---|
| 24 | quit
|
|---|
| 25 |
|
|---|
| 26 | :ShowIt
|
|---|
| 27 | echo ` the string is:`
|
|---|
| 28 | echo %string
|
|---|
| 29 | echo ` "@words[%string]" says there are `%@words[%string]` words in it`
|
|---|
| 30 | echo ` "@words[" ",%string]" says there are `%@words[" ",%string]` words in it`
|
|---|
| 31 | rem uncomment this if you want to see how @word parses the string
|
|---|
| 32 | rem do ctr = 0 to 20
|
|---|
| 33 | rem set aword=%@word[%ctr,%string]
|
|---|
| 34 | rem if "%aword" eq "" leave
|
|---|
| 35 | rem echo ` word `%ctr` is` %aword
|
|---|
| 36 | rem enddo
|
|---|
| 37 | rem echo ` which makes` %ctr `words`
|
|---|
| 38 | echo.
|
|---|
| 39 | return
|
|---|
| 40 | rem -----------------------------------------------------------------------------------------------
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|