By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,983 Members | 2,049 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,983 IT Pros & Developers. It's quick & easy.

Need an expression that will "filter" out 3 alpha-numeric characters in a string

P: 3
Hello,

I have a table that has a string field "ANUM" that has values that always begin with 089. Then the 3 characters; 089, are followed by between 3 or 4 characters. So a typical value in this field might be 089213 or 0895146. There will never be more than 4 characters, which follows that the total number of characters will not exceed 7.

What I need is an expression that will "filter" out the 089 values, leaving the remainder behind. So the aforementioned values of 089213 and 0895146 would result, after the expression is run, in 213 and 5146, respectively.

Thanks in advance for your replies!

Phil
Mar 20 '07 #1
Share this Question
Share on Google+
4 Replies


P: 60
I would use

Expand|Select|Wrap|Line Numbers
  1. Right(Str(intVariable), len(Str(intVariable)) - 3)
  2.  
If you specifically need the value returned as an integer instead of a string, you can use

Expand|Select|Wrap|Line Numbers
  1. Val(Right(Str(intVariable), len(Str(intVariable)) - 3))
  2.  
Mar 20 '07 #2

P: 60
Verbose Explination:
str(strVariable) returns the number stored in intVariable as a string (so if intVariable = 0891234, str(intVariable = "0891234")
That value is then passed to the len() function which returns the strings length (len("0891234") = 7)
Then 3 is subtracted from it (7 - 3 = 4)
So what we now have is this:
Val(Right("0891234", 4))
which returns the first 4 characters in "0891234" counting from the right [starting form the 4 in other words] (this returns "1234")
Finally, val() turns "1234" back into a number 1234.
Condensed Explination:
intVariable = 0891234
Val(Right(Str(intVariable), len(Str(intVariable)) - 3))
Val(Right(Str(0891234), len(Str(0891234)) - 3))
Val(Right("0891234", len("0891234") - 3))
Val(Right("0891234", 7 - 3))
Val(Right("0891234", 4))
Val("1234")
1234
Mar 20 '07 #3

P: 3
Thanks, your first option worked fine.

Cheers,

Phil
I would use

Expand|Select|Wrap|Line Numbers
  1. Right(Str(intVariable), len(Str(intVariable)) - 3)
  2.  
If you specifically need the value returned as an integer instead of a string, you can use

Expand|Select|Wrap|Line Numbers
  1. Val(Right(Str(intVariable), len(Str(intVariable)) - 3))
  2.  
Mar 20 '07 #4

P: 3
And Thanks for the both the Verbose AND the Condensed explanations!
Verbose Explination:
str(strVariable) returns the number stored in intVariable as a string (so if intVariable = 0891234, str(intVariable = "0891234")
That value is then passed to the len() function which returns the strings length (len("0891234") = 7)
Then 3 is subtracted from it (7 - 3 = 4)
So what we now have is this:
Val(Right("0891234", 4))
which returns the first 4 characters in "0891234" counting from the right [starting form the 4 in other words] (this returns "1234")
Finally, val() turns "1234" back into a number 1234.
Condensed Explination:
intVariable = 0891234
Val(Right(Str(intVariable), len(Str(intVariable)) - 3))
Val(Right(Str(0891234), len(Str(0891234)) - 3))
Val(Right("0891234", len("0891234") - 3))
Val(Right("0891234", 7 - 3))
Val(Right("0891234", 4))
Val("1234")
1234
Mar 20 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.