0

I wanted the leftmost string from a specific string.

Ex. sds_djfh_jdj I want sds for this I used the

LEFT('string',FIND("_",'string')-1)

but in my case another character may appear before the _ character

Ex. sds#_djfh_jdj (I want just sds but the formula that I use will give me sds#)

Can someone tell me how do I solve the problem.

JvdV
  • 70,606
  • 8
  • 39
  • 70

1 Answers1

2

As commented, you can include some OR logic within FIND. For all your cases it appears that the following would do just fine:

=LEFT(A1,MIN(IFERROR(FIND({"#";"_"},A1)-1,LEN(A1))))

Note: It's an array formula and need to be confirmed through CtrlShiftEnter

enter image description here

JvdV
  • 70,606
  • 8
  • 39
  • 70
  • But there's one thing which causes a problem when there is just the string that I want that is sds then the formula gives an error – Alex Sebastian May 06 '20 at 15:47
  • @AlexSebastian, please see update. If this answered your question do not forget to accept the answer (click the checkmark to the left of the answer) – JvdV May 07 '20 at 09:04