Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2653
  • Last Modified:

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
0
IO_Dork
Asked:
IO_Dork
  • 10
  • 4
  • 2
  • +2
1 Solution
 
mlmccCommented:
Try this
Assuming there will always be Acct#
Split({YourField},'Acct#')[2]

The formula using INSTR again assuming it is always there

Mid({YourField},InStr({YourField},'Acct#')+5)

mlmcc
0
 
IO_DorkAuthor Commented:
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?
0
 
Kent DyerIT Security Analyst SeniorCommented:
Probably going to need to use a MID or SUBSTR to do what you are looking for.

HTH,

Kent
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
IO_DorkAuthor Commented:
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?
0
 
mlmccCommented:
Try

Mid({YourField},InStr({YourField},'Acct'))
0
 
IO_DorkAuthor Commented:
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.
0
 
IO_DorkAuthor Commented:
Mid({YourField},InStr({YourField},'Acct')) does not work, CR still wants a starting position integer of 1 or greater.
0
 
IO_DorkAuthor Commented:
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?
0
 
IO_DorkAuthor Commented:
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)
0
 
mlmccCommented:
Does it always have Acct in it?

Are any of the fields NULL?

Try

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

mlmcc
0
 
SolracMCommented:
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.
0
 
James0628Commented:
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
0
 
IO_DorkAuthor Commented:
Field will never be null, it's an account name field.
0
 
mlmccCommented:
Have you tried the suggestions?
If so what are the results?

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

mlmcc
0
 
IO_DorkAuthor Commented:
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
0
 
IO_DorkAuthor Commented:
But I can always rely on there being a space before Acct in the field
0
 
James0628Commented:
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
0
 
IO_DorkAuthor Commented:
Close and works, but not a fool proof solution that I needed.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 10
  • 4
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now