Help with left() and right () functions


#1

Can somebody please help on how to get specific information from a variable. Say i have a variable with this value -

“abc 123 xyzzy”

I want to use that information and capture into a different variable, but only want the “123” part. How do i do that?

I think it has got something to do with the left and right function, but can’t seem to get it to work.

Any help?


#2

It would probably be easier to advise you based on a set of real example data, there are a number of ways to extract values from text but the effectiveness and simplicity of each will vary based on the actual shape of the data you’re working with.


#3

For example, the easiest case I could see from your sample is int('abc 123 xyz') which will give 123, but only if the real data in place of “abc” never includes numbers and your intention is to get the first number in some text.


#4

I’m doing this to get my speakers to remind me of TV shows coming from an RSS feed. Below is the description i’m saving into a variable.

I guess, i would want to always remove the first 14 characters and the last 34 characters. That would leave me the characters that are left in between. In this case being “Crisis on Earth-X, Part 1”


#5

I wouldn’t use hard-coded/fixed indexes. Just think what happens in May rather than November if you use a fixed number of characters from the end. You should trim the string based on content:

mid(description, 0, lastIndexOf(description, ' airs'))

will remove everything starting from (and including) the last " airs" in the string. I’m not exactly sure what the 3x08 at the beginning is (is that a pattern, channel number, fixed string, …?) but you could do something similar to trim the beginning (using indexOf() rather than lastIndexOf()). If you replace the 0 in the mid() function with the correct index based on content you can trim the string using one single mid() call.

Alternatively you could use replace() using regular expressions if that is more your thing (it would probably work better for the beginning of the string based on what those things mean and how exactly they are formatted).


#6

That was just perfect. Thank you so much!!