ShowAll Questionssorted byDate Posted
Linda 98

# Trim left and right parts of string in IF

I am using a Workflow field update and having IF conditions in it.
I want to trim left(6) and right(20) parts
My example is

'You can call on: 123456789 -thank you'

this is my string of which i want  only 123456789

IF(BEGINS(Info,'You can call on:  '),RIGHT(info,LEN(info) -15),
info))

This is giving me '123456789 -thank you'
I am struck with errors here.(If is not allowing me more than 3 conditions) Pointers please.
Best Answer chosen by Linda 98

Hi Linda,
I don't really see the the point of using IF in this particular scenario. But if you really want to use IF then you can do something like this.

MID(
Info,
FIND(":",Info)+1,
FIND("-",Info)-FIND(":",Info)-1
),
' '
)

To better understand the behaviour of IF refer to this link: https://help.salesforce.com/articleView?id=customize_functions.htm&type=5

Let me know if it helps.
Thanks

Sampath Suranji
Hi,
Try something like below,
IF(BEGINS(Info,'You can call on:  '),LEFT(RIGHT(info ,LEN(info ) -16),10),info))

best regards
From what I can understand you can use something like this:
IF(
CONTAINS(Info,'You can call on:') && CONTAINS(Info,'-thank you'),
MID('You can call on: 123456789 -thank you',18,9),'NULL'
)
This will work for the example you mentioned giving you the 9 digits.

Though your scenario is not making much sense to me. I might be to able to help you better if you can explain your requirement more clearly.
Jithesh Vasudevan
Use the below formula. It works,
IF(BEGINS(Info, 'You can call on'),RIGHT(LEFT(Info,27),10),'')
Linda 98
thank you.

i tired them but they are not working.All my values are not same always.
'You can call on:  767578697878768759765 -thank you

its not the number always.It might contain text also like

you can call on: 7677363737 ext 768 -thank you

I am trying to trim the center part and update it in custom field. YOu can call on: and -thank you are same always.
Alain Cabon
Hi,

Use nested SUBSTITUTE( ) moreover to remove the fixed values.

SUBSTITUTE(SUBSTITUTE(text, " -thank you","")," call on:","")

SUBSTITUTE(text, old_text, new_text) and replace textwith the field or value for which you want to substitute values,old_text with the text you want replaced, and new_text with the text you want to replace the old_text.

But your big problem is still the characters in the middle of the numbers like " ext " or " foo" or anything else that you don't know.
Hi Linda,
MID(
Info,
FIND(":",Info)+1,
FIND("-",Info)-FIND(":",Info)-1
)

Note: This will only give the expected results when there is no ':' or '-' between ' you can call on:' and '-thank you'.

Let me know if this helps.
Thanks.
Jithesh Vasudevan
Hi Linda,

Try this out,

TRIM(SUBSTITUTE(SUBSTITUTE( Info , '-thank you', ''),'You can call on: ',''))
Linda 98
i am having error when i use it .
as i am having other conditions,i am using IF

Can i use this in IF.I am having expected 3 but received 1 even i am using correct ()

Hi Linda,
I don't really see the the point of using IF in this particular scenario. But if you really want to use IF then you can do something like this.

MID(
Info,
FIND(":",Info)+1,
FIND("-",Info)-FIND(":",Info)-1
),
' '
)

To better understand the behaviour of IF refer to this link: https://help.salesforce.com/articleView?id=customize_functions.htm&type=5

Let me know if it helps.
Thanks

This was selected as the best answer
Sorna Jenefa

Hi,

Workflow Rule:

Rule Criteria  :   CONTAINS( image_te1__c ,'You can call on:') && CONTAINS(image_te1__c,'-thank you')

Field Update:

Phone field : MID('You can call on: 123456789 -thank you',18,9)

Text field  :  VALUE(MID('You can call on: 123456789 -thank you',18,9))

Kindly let me know will it works!

Thanks,
Jenefa
Sweet Potato Tec
Linda 98
My working code

IF( BEGINS(Info,'You can call on:  '),MID(Info,FIND("You can call on: ", Info)+16 ,
(FIND("-Thank you", Info )-10) - (FIND("You can call on: ",info ))),Info)

Thank you all.