Hello Everyone,
I'm working through yet another problem set, when the left() and right() functions threw me into a hole of confusion for the past hour where I've been engaging with ChatGPT to try and explain things to me.
Here's the expression:
if
left([_CurrentField_],1) = "S"
then
right([_CurrentField_],length([_CurrentField_]) - 2)
else
right([_CurrentField_],length([_CurrentField_]) - 1)
endif
Just some data, for the purposes of me trying to figure out what's going on:
[Unit Cost]
$10.00
[RRP]
S$11.00
So, the expression looks for a leading "S", if it finds it, it's supposed to delete two characters from the LEFT-MOST side. If it doesn't find an "S", then it deletes only one character from the LEFT-MOST side.
So, you'd end up with
[New_Unit Cost]
10.00
[New_RRP]
11.00
It seems straight-forward enough, but looking at the expression, I was completely dumbfounded. I looked the the right() function, and was thinking "the heck? why is right() deleting characters from the LEFT MOST SIDE?" shouldn't it be left(), instead of right()? Well, when I changed right( to left(, it ended up deleting the RIGHT-MOST characters, which amplified the confsion. I got something like this:
[New_Unit Cost]
$10.0
[New_RRP]
S$11.
Keep in mind, that I am not familair with programming, so if this is some fundamental aspect of that (like 0 is really 1, and 1 is really 2), then I'm not priviy to it.
To me, this seems very counter-intuitive, can someone please explain? I mean bless ChatGPT, but it tends to agree with everything I say, so I'm not really getting a straight answer there.
This is my broken, and not completely settled understanding of the functions, and please correct: with respect to the -2 option, left() and right() don't mean to start from the left-most or right-most positions, respectively. Instead, they tell you "direction of movement". So, right() means that you start from the left-most position and the -2 means you move to the RIGHT 2 characters, and remove everything to the left of that position; similarly, left() means that you start from the right-most position, and the -2 means that you move to the LEFT, 2 characters, and remove everyting to the right of that position.
If this is the case, as I said, it's really counter-untiitive and messy - at least to me.
Any any all help will be greatly appreciated.