Dear all
As the question title tries to summarize, assume I have a string variable; it is a long string, strL, in case that could matter. Within that string, I want to find a keyword, say "language". Then, I want to extract, say, x words before that keyword, and y words after that keyword.
Consider the example below. My keyword is "language", and I want to create new variables, that contain, for example, the 2 words before my keyword and the 4 words after my keyword. My guess is this can be done in elegant fashion, with a combination of regular expressions and string functions. I just am not able to figure out how to do it. Can you help?
Thank you in advance!
Hannes
As the question title tries to summarize, assume I have a string variable; it is a long string, strL, in case that could matter. Within that string, I want to find a keyword, say "language". Then, I want to extract, say, x words before that keyword, and y words after that keyword.
Consider the example below. My keyword is "language", and I want to create new variables, that contain, for example, the 2 words before my keyword and the 4 words after my keyword. My guess is this can be done in elegant fashion, with a combination of regular expressions and string functions. I just am not able to figure out how to do it. Can you help?
Code:
clear input strL stringExample "The definitions in the dictionary are simple and clarify the meaning. But for help with using the language, the examples are especially important, and the 7,500 frequent words are accompanied by a wealth of examples. These examples show a variety of significant features".
Hannes
Comment