# Determine if a word is in a text string

This should be simple. If a word is in a given text string the outpout should be true, else false. Can you please show me the code for this. I have searched on google, on reddit and on here. Even tried ChatGpt. I would like to use this to change the calendar day colour when a key word appears in my calendar notification. Thanks.

``````\$if( gv(day)!= "SUNDAY", false, true)\$

or

\$if( gv(day)= "SUNDAY", 1, 0)\$
``````

Actually I want to test for finding a word in a given sentence. Something like if(function(â€śhello worldâ€ť, â€śhelloâ€ť,),â€śtrueâ€ť,â€śfalseâ€ť). Then once I know it is working replace â€śhello worldâ€ť with a notification using the ni function.

I already tried different functions with the help of ChatGPT. But none of them worked.

I can use tc(regâ€¦ to replace a word if it is found in a sentence. So I suppose I could then compare the sentence with the original one, and if different the word was there. But that seems so convoluted.

If anyone needs this I am posting a solution. BUT it is convoluted - there must be a more direct code.

In this example if â€śsampleâ€ť is in the original sentence it will be replaced with â€śpickleâ€ť.

\$if(tc(reg, â€śThis is a sample sentence.â€ť, â€śsampleâ€ť, â€śpickleâ€ť)=â€śThis is a sample sentence.â€ť,0,1)\$

Here the equality is false because the word was found and replaced, but it outputs 1 to imply sample is in the sentence.

\$if(tc(reg, â€śThis is an example sentence.â€ť, â€śsampleâ€ť, â€śpickleâ€ť)=â€śThis is an example sentence.â€ť,0,1)\$

Here the equality is true because the sentence is unchanged, and outputs 0 implying â€śsampleâ€ť is not in the original sentence.

1 Like

You need to use the regexp operator, for example

`\$"this is a test" ~= is\$`

Will return 1 since sentence contains â€śisâ€ť

1 Like

Thank you! Wow so simple.

to be precise i think itâ€™s `\bis\b`.
using only `is` will also match `this` or `miss`. adding `\b` will only match `is`

1 Like

Thank you for that. Omitting the first letter of the word puts the inclusiveness to good use if the first letter might be upper case, and the word is long. E.g. holiday â†’ oliday.

a simpler way will be using tc(low) on the test text instead. omitting the first word might match undesirable word like boliday or coliday (not actual word, just theoretically. )

Yes. My approach was a hack, this is much more sensible. Thanks.

This topic was automatically closed 25 days after the last reply. New replies are no longer allowed.