A way to select certain strings from a message object.

kirkpearson's icon

Hi!

I'm working on a patch that finds particular sentences on Twitter and reads them aloud on a timer. I'm able to get the strings of text in, but am looking for a way of whittling down the string length in order to get the substring I want.

For example, when searching for the phrase "I am," I get something like this:

"ପଓ @Louis_Tomlinson ପଓ

i am catastrophically in love with you, and i'm so grateful for having you in my life ♡ follow me sunshine?
x15,915"

I'm looking for a way to pass this string through an object and edit it to cut off all the text before "I am" and after the next punctuation. That above string would turn into, for example:

i am catastrophically in love with you

Would anyone know how to do this?

Thanks!

vichug's icon
Max Patch
Copy patch and select New From Clipboard in Max.

you can do that with regexp but the trick here is that Max really hates the comma sign ( , ) and hence it will not recognize it inside a text
so the best i could do was that :

kirkpearson's icon

Ah! I should have thought of regexp. Thanks!

Why doesn't Max like commas?

vichug's icon
Max Patch
Copy patch and select New From Clipboard in Max.

Because it has special meaning : it means a separation between two messages. Actually you could circumvent it with atoi / itoa but it's another difficulty to regexp integer, because regexp works with characters so it's a bit tricky (you have to know the ascii code for each punctuation character and tell regexp to stop before them manually, but didn't find how to do it since the ^ character is not documented outside of Max and sparsely documented inside Max)