If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Search number in a string
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 |
#2
|
|||
|
|||
Search number in a string
On 25 Aug 2006 18:31:10 -0700, "Anna" wrote:
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(Re place(Replace(Replace(Replace([field],"0",""),"1",""),"2",""),"3",""),"4",""),"5","")," 6",""),"7",""),"8",""),"9","") John W. Vinson[MVP] |
#3
|
|||
|
|||
Search number in a string
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 Vinson wrote: On 25 Aug 2006 18:31:10 -0700, "Anna" wrote: 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(Re place(Replace(Replace(Replace([field],"0",""),"1",""),"2",""),"3",""),"4",""),"5","")," 6",""),"7",""),"8",""),"9","") John W. Vinson[MVP] |
#4
|
|||
|
|||
Search number in a string
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 wrote: 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 Vinson wrote: On 25 Aug 2006 18:31:10 -0700, "Anna" wrote: 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(Re place(Replace(Replace(Replace([field],"0",""),"1",""),"2",""),"3",""),"4",""),"5","")," 6",""),"7",""),"8",""),"9","") John W. Vinson[MVP] |
#5
|
|||
|
|||
Search number in a string
One approach is to use the rgxReplace() function at
http://www.j.nurick.dial.pipex.com/C...rgxReplace.htm with a pattern that catches digits and any spaces that precede them, e.g.: Dim S as String S = "Name Change Form 23124" S = rgxReplace(S, "\s*\d+", "") Debug.Print S Name Change Form On 25 Aug 2006 18:31:10 -0700, "Anna" wrote: 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 -- John Nurick [Microsoft Access MVP] Please respond in the newgroup and not by email. |
#6
|
|||
|
|||
Search number in a string
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 John Nurick wrote: One approach is to use the rgxReplace() function at http://www.j.nurick.dial.pipex.com/C...rgxReplace.htm with a pattern that catches digits and any spaces that precede them, e.g.: Dim S as String S = "Name Change Form 23124" S = rgxReplace(S, "\s*\d+", "") Debug.Print S Name Change Form On 25 Aug 2006 18:31:10 -0700, "Anna" wrote: 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 -- John Nurick [Microsoft Access MVP] Please respond in the newgroup and not by email. |
#7
|
|||
|
|||
Search number in a string
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). On 26 Aug 2006 13:55:53 -0700, "Anna" wrote: 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 John Nurick wrote: One approach is to use the rgxReplace() function at http://www.j.nurick.dial.pipex.com/C...rgxReplace.htm with a pattern that catches digits and any spaces that precede them, e.g.: Dim S as String S = "Name Change Form 23124" S = rgxReplace(S, "\s*\d+", "") Debug.Print S Name Change Form On 25 Aug 2006 18:31:10 -0700, "Anna" wrote: 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 -- John Nurick [Microsoft Access MVP] Please respond in the newgroup and not by email. -- John Nurick [Microsoft Access MVP] Please respond in the newgroup and not by email. |
#8
|
|||
|
|||
Search number in a string
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. John Nurick wrote: 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). On 26 Aug 2006 13:55:53 -0700, "Anna" wrote: 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 John Nurick wrote: One approach is to use the rgxReplace() function at http://www.j.nurick.dial.pipex.com/C...rgxReplace.htm with a pattern that catches digits and any spaces that precede them, e.g.: Dim S as String S = "Name Change Form 23124" S = rgxReplace(S, "\s*\d+", "") Debug.Print S Name Change Form On 25 Aug 2006 18:31:10 -0700, "Anna" wrote: 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 -- John Nurick [Microsoft Access MVP] Please respond in the newgroup and not by email. -- John Nurick [Microsoft Access MVP] Please respond in the newgroup and not by email. |
#9
|
|||
|
|||
Search number in a string
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. On 26 Aug 2006 14:44:39 -0700, "Anna" wrote: 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. John Nurick wrote: 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). On 26 Aug 2006 13:55:53 -0700, "Anna" wrote: 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 John Nurick wrote: One approach is to use the rgxReplace() function at http://www.j.nurick.dial.pipex.com/C...rgxReplace.htm with a pattern that catches digits and any spaces that precede them, e.g.: Dim S as String S = "Name Change Form 23124" S = rgxReplace(S, "\s*\d+", "") Debug.Print S Name Change Form On 25 Aug 2006 18:31:10 -0700, "Anna" wrote: 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 -- John Nurick [Microsoft Access MVP] Please respond in the newgroup and not by email. -- John Nurick [Microsoft Access MVP] Please respond in the newgroup and not by email. -- John Nurick [Microsoft Access MVP] Please respond in the newgroup and not by email. |
Thread Tools | |
Display Modes | |
|
|