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

Strip multiple non-numeric Characters from String

Status
Not open for further replies.

davidh5103

Technical User
Sep 24, 2001
3
US
I have a field which is designated as a string field. I need to find a formula strip a set of characters from that field. It just seems there should be an easy 1-line solution for specifying a set of characters to strip from a string but I havn't been able to think of one.
 
You can use the Left, Right, Mid, or Replace functions for what you want. The F1 files should steer you right, but if you're having trouble with syntax, post an example of what your field looks like, and say whether or not the string you want to get rid of is consistent.

Naith
 
Naith,

Thank you. I tried the replace function but I could not make it work with multiple characters. example

Replace({JobRecord.Job},("a","b","c",etc),"") I was unable to remove a consistent group of letters in this manner or when trying to use the IN function for the characters I wanted removed.
 
Are you just trying to eliminate the non-numeric portion of the string?

I think that you'll receive the best advice by posting sample data and desired output.

Some thoughts:

If you need to strip multiple chars from a string:

//Loop through the string and save what you want
whileprintingrecords;
global stringvar ResultString:="";
numbervar x;

for x = 1 to length(trim({MyTable.MyField}))
do(
if not(mid(({MyTable.MyField}),x) in ["A","B","C","X","Z"]) then
ResultString := ResultString+not(mid(({MyTable.MyField}),x)
)

That should get you close, I can't test right now.

There's probably a UFL that addresses this, and perhaps a more efficient means within CR that I can't think of right now.

-k kai@informeddatadecisions.com
 
I would suggest a different approach

There are only 10 numeric characters involved so why not just grab those on order and add them together

WhilePrintingRecords;
StringVar Temp := {Table.String_To_Be_Numeric};
StringVar Result := "";
NumberVar iCount;

for iCount := 1 to length(Temp) do
(
If isnumeric(Temp[iCount]) then
Result := Result + Temp[iCount];
);

Result;

this would eliminate all characters except numbers...if you wish to include say...a comma or decimal point just modify the "If" slightly
Jim Broadbent
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top