Best way to convert Nominal values by using expressions
Doomy
New Altair Community Member
I’ve set of data with INCH measurement unit , the values are so missy and I’m trying to figure out a way to unified them and convert them to a way I can work with them
Example of the values :
If there’s any other way to solve this issue I would appreciate any suggestions to solve that.
Example of the values :
- 1/8 , 1/16 , 19/17 , 13/3 , 1.1/8
- 0.139 , 0.07 , 3.37 , .250 , 0.14
- 3-1/8 , 1-1/26 , 1-18/23 , 10-1/2
- 20 , 3 , 10
- 0.30-0.40
- 0.094+/-0.004
- 1.046 ( 1-1/16)
- Some of them have text and numbers
If there’s any other way to solve this issue I would appreciate any suggestions to solve that.
0
Best Answer
-
Don't know too much on how inches work, but since your values seem seperated by comma's you could use that to split the strings into single values. If you want to keep inches you can than normalize these by replacing '-' to '.' or the other way around.
If you need to convert to mm you can than generate a regex that converts the full inches and the 'sub inches'. Not sure how it's really called...
As an example, if you have 3-1/16 and have a regex like this :
^(d+)?[.-]?(?:(\d+)/(\d+))?
You read this like 'you start with optional full digits, followed by an optional hyphen or dot, and then you have the optional divider.
Your first group would be 3, the second 1, and the third one 16, so you could create something like
($1 * 25.4) + ((25.4 / $2)/$3) to convert to mm. I have no clue if my conversion is correct by the way, but you get the idea.
Now, this works if you have a full match, in case of partials like 2/16 (so no full digits) or 20 (so no divider) it means your replacement needs to be adjusted0
Answers
-
Don't know too much on how inches work, but since your values seem seperated by comma's you could use that to split the strings into single values. If you want to keep inches you can than normalize these by replacing '-' to '.' or the other way around.
If you need to convert to mm you can than generate a regex that converts the full inches and the 'sub inches'. Not sure how it's really called...
As an example, if you have 3-1/16 and have a regex like this :
^(d+)?[.-]?(?:(\d+)/(\d+))?
You read this like 'you start with optional full digits, followed by an optional hyphen or dot, and then you have the optional divider.
Your first group would be 3, the second 1, and the third one 16, so you could create something like
($1 * 25.4) + ((25.4 / $2)/$3) to convert to mm. I have no clue if my conversion is correct by the way, but you get the idea.
Now, this works if you have a full match, in case of partials like 2/16 (so no full digits) or 20 (so no divider) it means your replacement needs to be adjusted0