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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting numbers from a string

Status
Not open for further replies.

ukleaf

Programmer
Mar 16, 2004
27
GB
Hi all,

is there an easy way in Crystal to extract a number from a string?

Basiclly the number within the string will always be set out like this,

String line then number amount - £100.00 -

thanks.
 
Maybe.

So is the pattern ALWAYS:

xxxxxx...xxxx dash poundsign amount dash

And can it be said that the xxxx..xxxx will NEVER contain a dash or a poundsign. Are the amounts ALWAYS positive?
 
Hi there,

Yes the text will always be the same up to the - and the £, just the amounts will vary... there will also be a - after the amount too, e.g.

XXXXXX XXXXXXX .... - £1000.00 -
XXXXXX XXXXXXX .... - £23.00 -
...
...

Thanks
 
Use this formula, modified with your own tabl/field names.

numbervar vStart;
numbervar vEnd;
vstart:= instr({mytable.myfield},"£");
vend := instr(vstart,{mytable.myfield},"-");
mid({mytable.myfield},vstart,vend-vstart)
 
Great, thanks very much. I'll give it a try and let you know.

Thanks again.
 
You could also use something like this if you want the "£" included:

split({table.field},"-")[2]


If you don't want the "£" included, this should work for you:

val(split({table.field},"-")[2])

~Brian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top