Have parameter that is 914klm5ft12or3467 that is a string
i want to filter numbers and put in a parameter that is REAL like 9145123467
I can only see this in an extensive -IF- clause that evaluates each entry in the string as a valid "numeric" string that represents a number and next, determine the length of the full number string... and create variables, again based on an extensive -IF- to determine the value of each string"number".
(capture every character as a variable)
(evaluate every variable purging alpha characters)
(Determine the string length)...
(multiply each variable by 10,100, 1000, 10000, 100000, etc...)
(add all the variable together)
Would I want to write this? NOPE!
We need a simple function that will parce a value from a text string by purging non-numeric characters.
As for the OP's request, I would reverse the requirements by making the string from the values rather than making the value from the string.
this parameter evaluates some extracted values from tables "extract(TABLE_1,1,3)", "extract(TABLE_1,3,6)"
in old files case evaluates the modelname parameter (that is a string) and compose with extracts the "NUMBERCAD" parameter that drivers the numbering in pdm
in othe case i have to extract only numbers to acquire gps coordinates or absolute coordinates (that are comma separated values)
all those things are acquired as strings and shall be filtered and turned in to numbers
in case of user fantasy he puts all the caracters on the keyboard as many he is inspired to do
but i care only for numbers so the filename and number should be real numbers
in case of acquire gps coordinates in other parameters is the same, or coordinates from a fem analisys
than from this parameter "NUMBERCAD" that is a string (because model_name is a string) try to filter and get only numbers.
in creo relation there in no way to extract FROM a string TO a number, but is only possible to do the opposite with this command "extract(PARAMETER,3,6)" (extract from third value of parameter 3 following values)
also i should reverse the requirements but you can't drive new file name in creo and you can't put filters on creation
Using the jlink(java)/weblink(java script)/VBA(vb) toolkits provided with Creo it should be a fairly simple task.
The must elegant solution would be to use the regular expressions API.
Unfortunately you can not call regex functions from within Creo relations (what a shame), but they are supported in most programing languages.
Here is how the code might look like in VB.NET
Dim mystr As String = "914klm5ft12or3467"
MsgBox(Regex.Replace(mystr, "[^\d]", ""))
Indeed, not directly. But you can query each character in a string and see if it is a string equivalent to a number. If the query returns true, you assign a number to a new variable and multiply it according to the position in number string.
So then, length of the string remains as an issue. One of two issues actually. You can use string_length relation function to find out how long is the string.
If the length of the part name varies too much, and you can't tell what could be the possible maximum length of the string in characters, then I can't really think of any solution. But if you can set the cap number that matches your longest string length then you might be able to get the numbers after it goes through all relations. While adding dummy numbers or characters to each of your strings so they always match the preset length.
Imagine you will for example have to test 48 characters in total, and you will be testing them all in such a way that Antonius has suggested above. Some will and some won't be numbers, now how to go around with the concatenation of the numbers into a new string? That's the question.
I'll stop trying to pull you into the problem right here, cause it might be too huge. Converting a string number into a real number is another one, but it might just be a piece of cake compared to the first one.