Search number in a string

  • Thread starter Thread starter Anna
  • Start date Start date
A

Anna

How to check a number in a string. Some times i have values contains
numbers some times dont. I try split but it gives error when there is
no number in the string. What i need is to check the string if it not
contains numbers than ok otherwise i have to remove the number from the
string

Subject
Name Change Form
Name Change Form 23124

Thank You
 
How to check a number in a string. Some times i have values contains
numbers some times dont. I try split but it gives error when there is
no number in the string. What i need is to check the string if it not
contains numbers than ok otherwise i have to remove the number from the
string

Subject
Name Change Form
Name Change Form 23124

Thank You

A criterion of

LIKE "*[0-9]*"

will return records where the field contains a digit anywhere within
the string.

To blindly remove all digits from a string, without tripping an error
when there are none, you can use a snarky nested Replace() function:

Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace([field],"0",""),"1",""),"2",""),"3",""),"4",""),"5",""),"6",""),"7",""),"8",""),"9","")


John W. Vinson[MVP]
 
How does your string get its values? If users enter it in a form, you
can use the mask property of the field to accept only alphabetic
characters (if that is what you need in the string)

John


John said:
How to check a number in a string. Some times i have values contains
numbers some times dont. I try split but it gives error when there is
no number in the string. What i need is to check the string if it not
contains numbers than ok otherwise i have to remove the number from the
string

Subject
Name Change Form
Name Change Form 23124

Thank You


A criterion of

LIKE "*[0-9]*"

will return records where the field contains a digit anywhere within
the string.

To blindly remove all digits from a string, without tripping an error
when there are none, you can use a snarky nested Replace() function:

Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace([field],"0",""),"1",""),"2",""),"3",""),"4",""),"5",""),"6",""),"7",""),"8",""),"9","")


John W. Vinson[MVP]
 
Thanks for reply. I parse values from a textfile so there is nothing
with the database. Some times text file contains subject with numbers
which i have to remove during parsing.

J. Goddard said:
How does your string get its values? If users enter it in a form, you
can use the mask property of the field to accept only alphabetic
characters (if that is what you need in the string)

John


John said:
How to check a number in a string. Some times i have values contains
numbers some times dont. I try split but it gives error when there is
no number in the string. What i need is to check the string if it not
contains numbers than ok otherwise i have to remove the number from the
string

Subject
Name Change Form
Name Change Form 23124

Thank You


A criterion of

LIKE "*[0-9]*"

will return records where the field contains a digit anywhere within
the string.

To blindly remove all digits from a string, without tripping an error
when there are none, you can use a snarky nested Replace() function:

Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace([field],"0",""),"1",""),"2",""),"3",""),"4",""),"5",""),"6",""),"7",""),"8",""),"9","")


John W. Vinson[MVP]
 
This function works fine only one thing is some times the value is:
Subject
Name Change Form - 23124
Subject = rgxReplace(Subject, "\s*\d+", "")

This function returns the value
Name Change Form -

Does this possible that it removes the hypen sign too

Thank You
 
Hi Anna,

Try it with this regular expression
\s*-?\s*\d+

Each \s* matches zero or more spaces (or tabs), and the -? matches a
hyphen if there is one (zero or one hyphen).
 
Thanks a loot you are very sweet. I would be greatfull if you please
tell me how you make this expression or any link/tutorial by which i
can get this expression by myself.

Thanks again,

Anna.
 
On this page http://www.j.nurick.dial.pipex.com/Code/index.htm and on
the one I originally referred you to, there's a link "More about regular
expressions". That will take you to a page with links to information on
using regular expressions.

Thanks a loot you are very sweet. I would be greatfull if you please
tell me how you make this expression or any link/tutorial by which i
can get this expression by myself.

Thanks again,

Anna.
 
Back
Top