Hello All,
My requirement is to search a word from the sentence.
for example: sentence(single text): "The document is AI contain the data"
search text :"AI"
Output: true
The desired result is:- get that the sentence is having the search text but only if exact word is there no if that alphabet is any word.
For example: "The document contain the data"
search text: "ai".
output: false
regards
sahil
Discussion posts and replies are publicly visible
Hi sahilb0004, You can use find() or search() function to check if a word is there or not in your text and then add a condition to get the boolean value. find or search function gives you the index of the word you are searching in the text string. so if you get 0 as a result then it means the word you searched is not available hence you can get output as false and if it gives any non zero integer , it means you found the word in your text string. See below example.
a!localVariables( local!position:find("AI","The document is AI contain the data",), if( local!position=0, false, true ) )
You can use the substitute method. Use to substitute the desired searchText and then compare the length of the old and new string. If the text was found, then the length of the string will be reduced by searchText characters.
I highly recommend to become familiar with the Appian function library.
docs.appian.com/.../Appian_Functions.html
Because you want to explicitly find if the object is a word (not letters within another word), I don't think you can directly use find / search / substitute. Instead, I'd recommend splitting all the words in your sentence by a space and then comparing each word individually. Here's an example:
a!localVariables( local!sentence: "The document is AI and contains the data", or( a!forEach( items: split(local!sentence, " "), expression: fv!item = "AI" ) ) )
Depending on what you expect your text input to be, you might need other logic as well. For instance, if you expect to receive multiple sentences or punctuation, I'd also recommend stripping out all of the punctuation before doing the check using the stripwith() function.