Solved

Exracting Number from string

Posted on 2013-06-14
3
284 Views
Last Modified: 2013-06-26
I am using CR 2008

I have a text field in my report at present, it is manly in the format as below

Joe Bloggs - 01326839 -00000001 - Letter
John Smith - 2526261/2 - Memo
John Smith - 2526261 - 1 - Memo

There are variations like
1011121/2 - Letter

In each case I would like to extract the numbers in the text field, using the examples above the result would be

01326839 - 00000001
2526261/2
2526261 - 1
1011121/2

Is this possible?
0
Comment
Question by:halifaxman
  • 2
3 Comments
 
LVL 100

Expert Comment

by:mlmcc
ID: 39247944
You want to capture everything from the first digit found until a non-digit, / , -, and SPACE is found?

Any other variations?

mlmcc
0
 
LVL 77

Accepted Solution

by:
peter57r earned 500 total points
ID: 39247953
Have a go with this...


numbervar x:=0;
numbervar y:=0;
numbervar z:=0;
stringvar s1:="";

stringvar OK1:="1234567890/-";

stringvar inval:= {table.fieldname};        //YOUR fieldname here
z:=len(inval);
for x:=1 to z do
if inval[x] in OK1 then s1:=s1 & Inval[x];

//step 2
while s1[1]  in ["-","/"] do
s1:=mid(s1,2);

//step3
while right(s1,1) in ["-","/"] do
s1:=left(s1,len(s1)-1);

s1
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 39247994
I think that is close but it doesn't include the blanks and it will return embedded numeric like

John1 Smith - 4321/345 - Memo

The blank is easy, just add it to the OK1 string
    stringvar OK1:="1234567890 /-";

Also need to include the blank when stripping leading and trailing characters

mlmcc
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

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. …
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

821 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