Jakub, you would use a counter as you were parsing numeric characters. Every time you get a hit, you add 1 to the counter. At the end of the string, you know how many number characters you accumulated. At that time you know what the multiplyer needs to be for every single numeric value.
Good idea. Now to figure out how to do the concatenation of numbers. This code if ever made will be long like forever.
I won't tackle this one. But it is a good discussion none the less.
It does add to the argument that the functions in Creo are seriously lacking by today's standards.
Yeap, I won't bother writing the whole code for this either, but I thought about this for few more mins, and it really might not be that hard after all.
First of all, there can be only up to 31 chars in a partname. That means the counter would only require 31 If statements, each with a little long condition to check if the character is any of the ten numbers.
Could really use a For loop statement there.
Then also, I figured out that during the concatenation of the first string to separate all number characters, it's possible to pass in empty values. See the folowing picture.
But the number of numeric characters can be in theory 31 as well. So that makes 31 new If statements while each of these need to be converted to a real value, that makes 10 another If statements under each of these 30 Ifs. So, that's another 161 If statements. These could give you the information about position of the character in this new numeric string, which would make it easier to convert it to a real number at the end. You could actually do the conversion within these 31 If statements.
Umm, does that mean it would take about 200 If statements in total? While normally it could take just 3 functions, where each function would contain just one For loop. It sounds too silly.
Well, on the other hand if you can write this for just 3 characters long string, and make it work, then for a 31 characters long string it's all just a matter of copying, and pasting.
A few minutes thinking huh
I like the concatinated_string. Forgot about that.
But you wouldn't need 31 if's... you only need 10 if's to parse numbers and the rest fall under "else".
You just have to be careful with 0 (zero) because in some cases is returns an empty string (I forget which cases).
I really think would need this many Ifs, 10 for each of 31 chars. Of course these 10 Ifs would be relevant only to the character containing a number, but you would still need to define them also for characters not containing letters.
This comes from few mins of dumb thinking. That means I could be wrong.
The example you wrote up above there in one of your posts should work fine with zeros.
I'd base it on something like this:
digitlist = "0123456789"
value = 0
digit_found = search(digitlist,extract(rel_model_name(),len(rel_model_name)-0,1)-1
value = value+digit_found
digit_found = search(digitlist,extract(rel_model_name(),len(rel_model_name)-1,1)-1
value = value+digit_found*10
digit_found = search(digitlist,extract(rel_model_name(),len(rel_model_name)-2,1)-1
value = value+digit_found*100
digit_found = search(digitlist,extract(rel_model_name(),len(rel_model_name)-3,1)-1
value = value+digit_found*1000
This was to clip numbers at the ends of parameters. In your case I would have the logic start with the first one and use
IF digit_found <> 0
value = value*10 + digit_found.
Then wrap the digit_found ... and IF digit_found ... in an
IF len(parameter)> whatever_step
value = ...
Repeat for whatever_step = 1 to whatever the maximum number of characters you expect.
Since it's an integer, ITOS() should work OK if you need a string.
This was exactly what I was looking for. In my case, I wanted to convert the last 3 characters (string) from our part name to a number.
I have shortened the code just a little bit more:
DIGITS = "0123456789"
TEMP = 0
TEMP = TEMP+(SEARCH(DIGITS,EXTRACT(REL_MODEL_NAME,STRING_LENGTH(REL_MODEL_NAME)-0,1))-1)*1
TEMP = TEMP+(SEARCH(DIGITS,EXTRACT(REL_MODEL_NAME,STRING_LENGTH(REL_MODEL_NAME)-1,1))-1)*10
TEMP = TEMP+(SEARCH(DIGITS,EXTRACT(REL_MODEL_NAME,STRING_LENGTH(REL_MODEL_NAME)-2,1))-1)*100
You can extend this for as long as you like.
Just one warning, there is no error checking!
Keep in mind that you're going to get a negative 1 any time this encounters something other than a number (anything not present in DIGITS.)