Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extract numeric value from string field

Status
Not open for further replies.

IceRuby

Technical User
Jan 20, 2004
85
AU
Hi there
Using Crystal Version 9 to MS SQL database.
I am filtering a field with following formula:-
(@buffer) = {buffer.response} like "GetSpecificRecord*"

It extracts values as below. I now need to extract the numbers from these fields. (see samples below)

Sample returned values:-
GetSpecificRecord(9000707)
GetSpecificRecord(9002117, 1st)
GetSpecificRecord(9008888,9000456)

Need to extract:-
9000707, 9002117, 9008888, 9000456 each as own fields.

Appreciate your thoughts and thanks in advance
 
Do all the numbers begin with 9?
Are they all the same length?

How many numbers can there there be?
What are you expecting to do with the numbers?



 
I think that you'll need a loop for this since these are strings, not numbers:

OK, here's a formula to populate an array and convert each element to either N/A or a numeric value:

whileprintingrecords;
Stringvar InString := replace(replace("GetSpecificRecord(9000707,1st)","GetSpecificRecord(",''),")",'');
StringVar array MyArray := split(InSTring,",");
//join(MyArray,chr(13))
numbervar x;
StringVar array OutArray := split(InSTring,",");
For x:= 1 to ubound(MyArray) do(
if isnumeric(MyArray[x]) then
OutArray[x] := MyArray[x]
else
OutArray[x] := "N/A";
);
join(OutArray,chr(13))

You didn't state what you intended to do with these individual elements, and if you don't want the N/A replace it with "".

SO now that they're extracted, you can do what you want with them, but in the future I'd suggest stating how you intend to use them, as further processing may be required.

-k
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top