Solved

Extracting text from long string after certain word

Posted on 2013-01-01
18
2,203 Views
Last Modified: 2013-01-10
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
Comment
Question by:IO_Dork
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 4
  • 2
  • +2
18 Comments
 
LVL 101

Accepted Solution

by:
mlmcc earned 500 total points
ID: 38735457
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
 

Author Comment

by:IO_Dork
ID: 38735466
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
 
LVL 17

Expert Comment

by:Kent Dyer
ID: 38735471
Probably going to need to use a MID or SUBSTR to do what you are looking for.

HTH,

Kent
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:IO_Dork
ID: 38735476
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
 
LVL 101

Expert Comment

by:mlmcc
ID: 38735481
Try

Mid({YourField},InStr({YourField},'Acct'))
0
 

Author Comment

by:IO_Dork
ID: 38735482
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
 

Author Comment

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

Author Comment

by:IO_Dork
ID: 38735496
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
 

Author Comment

by:IO_Dork
ID: 38735500
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
 
LVL 101

Expert Comment

by:mlmcc
ID: 38735523
Does it always have Acct in it?

Are any of the fields NULL?

Try

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

mlmcc
0
 
LVL 3

Expert Comment

by:SolracM
ID: 38735587
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
 
LVL 35

Expert Comment

by:James0628
ID: 38739269
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
 

Author Comment

by:IO_Dork
ID: 38739975
Field will never be null, it's an account name field.
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 38740937
Have you tried the suggestions?
If so what are the results?

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

mlmcc
0
 

Author Comment

by:IO_Dork
ID: 38742472
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
 

Author Comment

by:IO_Dork
ID: 38742475
But I can always rely on there being a space before Acct in the field
0
 
LVL 35

Expert Comment

by:James0628
ID: 38743082
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
 

Author Closing Comment

by:IO_Dork
ID: 38763690
Close and works, but not a fool proof solution that I needed.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question