Hello Philip and Martin,
Thank you both for valuable help. Before I jump in at the deep end, I would first like to address some of Philips corrections and suggestions.
phspaelti wrote: ↑2021-03-29 07:02:43
The Find command will return the number of find hits, which in this case should always be 1.
It seems I had forgotten about that. Thanks for reminding me.
if you want to test a variable you will need to use the double equal sign "==", not just a single one.
A cardinal sin. I will remember that.
And you could of course use logical OR (written with a double pipe '||') to test all 10 digits
I tried this, and although a number was found, it doesn't work. What am I doing wrong this time?
$number = Find @Text<\X>, 'E'
if $number == "1||2||3||4||5||6||7||8||9||0"
prompt "It's a number!!"
end
I found this double pipe only twice in the Macro Language Reference, and there was no mention of OR in connection with the double pipe, or I didn't understand it. I know a single pipe in regex means OR. Where can I learn more about a double pipe and how to use it?
I'd also like to point out that a more direct way to get the character you want to test is to use the macro language:
$sel = TextSelection.active
$theFoundCharacterRange = Range.new $sel.location - 1, 1
$theFoundCharacter = $sel.text.substringInRange $theFoundCharacterRange
If you understood all that you can now squeeze the whole logic into one statement like this:
$sel = TextSelection.active
if $sel.text.substringInRange(Range.new($sel.location - 1, 1)).find('\d','E')
prompt 'digit'
else
prompt 'not a digit'
end
But whether that's recommended is another question
This truly reminds me of Mark Twain's essay
The Awful German Language (1880):
"There are ten parts of speech, and they are all troublesome. An average sentence, in a German newspaper, is a sublime and impressive curiosity; it occupies a quarter of a column; it contains all the ten parts of speech — not in regular order, but mixed; it is built mainly of compound words constructed by the writer on the spot, and not to be found in any dictionary — six or seven words compacted into one, without joint or seam — that is, without hyphens; it treats of fourteen or fifteen different subjects, each inclosed in a parenthesis of its own, with here and there extra parentheses which reinclose three or four of the minor parentheses, making pens within pens: finally, all the parentheses and reparentheses are massed together between a couple of king-parentheses, one of which is placed in the first line of the majestic sentence and the other in the middle of the last line of it —
after which comes the VERB, and you find out for the first time what the man has been talking about; and after the verb — merely by way of ornament, as far as I can make out — the writer shovels in "
haben sind gewesen gehabt haben geworden sein," or words to that effect, and the monument is finished."