>>>>Hi everybody,
>>>>
>>>>I have a character string representing Style which consists of the following portions:
>>>>
>>>>Color (1 letter with - or without -) Type (one or 2 letters) Number portion (could be any number but usually no more than 5 digits and not less than 2) then Stone (1 letter) then quality (number) then color quality (1 letter), e.g. for example:
>>>>W-4568S5B
>>>>E460D4
>>>>E94E
>>>>
>>>>Now, all these portions are optional except for number portion. My task is to get the number portion first, then try to search, if we have a file with the same number, same first portion, same stone (if it was present), different quality. Then if there are no files with the same stone, I need to do other string manipulations.
>>>>
>>>>Can you help me to get Number portion first?
>>>>
>>>>Thanks in advance.
>>>
>>>try
>>>
>>>? str(ABS(val(SUBSTR('W-4568S5B',2))))
>>>? str(ABS(val(SUBSTR('E460D4',2))))
>>>? str(ABS(val(SUBSTR('E94E',2))))
>>>
>>
>>There is a catch here, with E after the number and a number, like E94E5. Also there could be situation when I don't have the first letter, or have NK as the first portion.
>>
>
>You change the issue, here :)
>
>>I'm thinking: replace all letters and - with some common letter, say, X. Then apply alines() function using X as delimiter. This way I would get my number portion and also a quality, if it present.
>
>general solution, for the first number word
>
>CLEAR
>
>? GetFirstNaturalWord("E94E5")
>? GetFirstNaturalWord("E-904E5")
>? GetFirstNaturalWord("NK94E5")
>? GetFirstNaturalWord("94E5")
>? GetFirstNaturalWord("94"+SET("Point")+"56E5")
>
>PROCEDURE GetFirstNaturalWord(s)
> RETURN CAST(CAST(CHRTRAN(m.s,CHRTRAN(m.s,"0123456789",REPLICATE(CHR(0),10)),SPACE(246)) AS I) AS M)
>
>
>If you want to split the string into many attributes, ALINES() it is the way.
>
>However, without a well defined separator,
>to merge different data in a string is a coarse error,
>and the problems will arrive very soon.
I agree with your last comment. I think, we actually may have each attribute in a separate field as well. It's just the particular procedure deals with Style only, which as I said is a combination of the attributes. Perhaps the procedure itself can be adjusted to do a search in Styles table by style and get the attributes, then start playing...
If it's not broken, fix it until it is.
My Blog