Link to home
Start Free TrialLog in
Avatar of IO_Dork
IO_DorkFlag for United States of America

asked on

Extracting text from long string after certain word

I am trying to only display certain text from a field with a long string.  

If field is:
"Some Investor With a Long Title Acct#:123456789"

I want to create a formula field that looks for the "Acct#:" and returns all string data from the word "Acct#:" all the way to the end of the string.  i.e. "Acct#: 123456789".  The "Acct#:" will always be at the end but the account number will vary in length, so a Right() function will not suffice.  I tried playing around with the Instr() function but did not get very far with it.

Thanks
Brian
ASKER CERTIFIED SOLUTION
Avatar of Mike McCracken
Mike McCracken

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of IO_Dork

ASKER

When using split I get the error "A subscript must be between 1 and the size of the array.

my formula field:
Split({investor.i_letter1},'Acct#')[2]

Some have a space between "Acct" and "#" and some don't, so I just left out the "#".
i.e. - Split({investor.i_letter1},'Acct')[2]

However, I noticed that some account titles contain "ACCT", or "Acct"....is this formula Case Sensitive?
Probably going to need to use a MID or SUBSTR to do what you are looking for.

HTH,

Kent
Avatar of IO_Dork

ASKER

The problem with the  Mid({YourField},InStr({YourField},'Acct#')+5) formula is that although it works, the +5 cuts out the "Acct#" string....I want to include the Acct# along with everything that follows it.  Putting in a 0 does not work as the formula wants a starting position integer greater than 0.  any suggestions to get around this?
Avatar of Mike McCracken
Mike McCracken

Try

Mid({YourField},InStr({YourField},'Acct'))
Avatar of IO_Dork

ASKER

Although, a crude solution is to add a space infront of the "Acct#" in the formula then just use +1 as the starting position so that it starts returning text at the "A" of the string "Acct#"....I'd rather find a cleaner and more correct way to accomplish this, but if this is the only way then I can settle for it.  Let me know what you all think.
Avatar of IO_Dork

ASKER

Mid({YourField},InStr({YourField},'Acct')) does not work, CR still wants a starting position integer of 1 or greater.
Avatar of IO_Dork

ASKER

the mid also does not work properly if there is a difference in case...is there a way to address this in the formula to be case insensitive?
Avatar of IO_Dork

ASKER

think i just figured out the case sensitive issue.  I added ",1" after the 'Acct' part of the formula. let me know if this is correct.

Mid({investor.i_letter1},InStr({investor.i_letter1},' Acct',1)+1)
Does it always have Acct in it?

Are any of the fields NULL?

Try

Mid({YourField},InStr(UCase({YourField}),'ACCT'))

mlmcc
sounds like a job for a plumber is this Php? can you use pipes in Php? you can PIPE in strings and drop then drop literals out of the pipe.

PIPE > var1,1  | drop ......| > var1
sorry if I am way off I am an old mainframe Plummer (cms pipes) and it has been a long time.
I thought the concept of pluming has been ported to other platforms.
Yes, adding the 1 argument to InStr should handle the case issue.

 FWIW, if the field does not always include "Acct#", you could handle that by checking the result from InStr first.  Then you don't have to rely on there being a space in front of "Acct#".

if InStr({investor.i_letter1},'Acct',1) > 0 then
  Mid({investor.i_letter1},InStr({investor.i_letter1},'Acct',1))
else
  {investor.i_letter1}


 Put the result that you want to see when the field does not include "Acct#" after the "else" (eg. the field, or "" to get an empty string).

 If there will always be a space in front of "Acct#", then what you have in that last post seems fine, and would probably be a bit more efficient, since it only uses InStr once.

 FWIW, if the field could be null, that may be something that you need/want to handle as well.

 James
Avatar of IO_Dork

ASKER

Field will never be null, it's an account name field.
Have you tried the suggestions?
If so what are the results?

How do the results differ from the expected or desired result?

mlmcc
Avatar of IO_Dork

ASKER

The only solution that works is the one I mentioned...putting space I front of the word Acct and a +1 for the starting point, won't work without a starting int > 0
Avatar of IO_Dork

ASKER

But I can always rely on there being a space before Acct in the field
Well, like I said, you could test the result from InStr first to make sure that it's not 0.  That will work too (unless there's some other factor involved that I'm not aware of).  But if the space will always be there, then your way is fine.

 James
Avatar of IO_Dork

ASKER

Close and works, but not a fool proof solution that I needed.