Solved

Extracting text from long string after certain word

Posted on 2013-01-01
18
1,959 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
  • 10
  • 4
  • 2
  • +2
18 Comments
 
LVL 100

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
 

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 100

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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 100

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 34

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 100

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 34

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Selection formula 7 41
Error when running Crystal Report in BI 2 39
Crystal Reports Sub Report 4 71
Multiple Parameters in Crystal 11 33
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. …
Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now