metropoj
21st June 2007, 22:43
Been looking through the WIKI on string operators and I can't find what I'm hoping exists.

We create in the Product configurator a 31 character text string like this :

"Length: 123.0000m +-15mm "

I need to copy into a string variable everything AFTER the meterage in the string. In other words, I want to extract "+-15mm" from the string. Once the string is trimmed, the +-15mm is pretty well constant as far as spacing it takes ( all tolerances are 6 characters long )

I cannot find any advanced operators for extracting within a string. Can anyone point me to the right direction ? Thx !

_Ralph_
21st June 2007, 23:08
U can use string.scan


domain tcmcs.str256 primary.string
domain tcmcs.str256 secondary.string

primary.string = "Length: 123.0000m +-15mm "

string.scan(primary.string, "m%s", secondary.string)

|* Now secondary.string = +-15mm




Hope it helps! :)

metropoj
22nd June 2007, 15:06
OH, OK, I see. Thankfully there is no M in before the metrage :) ....

I'll try that out. \\BTW, what does the S stand for at the end ? I presume that 's' could be anything except a value between the m and the end of the string ?

I'll give it a shot, thanks again ...

mark_h
22nd June 2007, 15:15
The m is the separator and the "%s" means the remaining string. Look at the sprintf command to see what else you could do with the format string.

metropoj
22nd June 2007, 18:42
Well, since I am looking at a numeric reference in my code, I have to use a text.to.buf conversion too.

This meant my string vars to the following array style.

extern string ordered_length(23,1)
extern string field_cut_length(28,1)

text.to.buf("tipcs021.txta","2",1,ordered_length)

string.scan(ordered_length(23,1),"m%s",field_cut_length(28,1))

Now, I origianlly had both these string fields set to 30.

ordered_length grabs text "Length: 40.0000m +/-15mm ". This one seems to work just as expected.

BUT, when I do string scan I would get nothing with more than 29 characters in the string.I found out the problem was when I scanned in past the next 'm' in ordered_length :( ... then it gives me nothing .. can't even view the variable at all.

something else that was strange, field_cut_length in debug gave me " -" as the result, so it doesn't seem to be picking up the scan properly ... pads in pile of blank spaces, so I must be off with the string.scan function.

I tried numerous lengths of strings for testing but anywhere past the position when a second 'm' pops up, there is nothing ... Strangeness ..

mark_h
22nd June 2007, 18:55
Is this the actual command you used - string.scan(ordered_length(23,1),"m%s",field_cut_length(28,1))? I think it should be string.scan(ordered_length(1,1),"m%s",field_cut_length(1,1)).

metropoj
22nd June 2007, 19:05
Ah, you see, when I tried the 1,1 earliser, I also changed my string variables to the same.

This time I left them as declarations of 30,1 and 30,1 and changed the string.scan as you suggested.

I don't think i fully understand the difference between why my declarations have to show all 30 characters of the string and why string.scan only needs (1,1). I thought it needed to scan all the 30 places of my string declar. Darn ...


Now, I say one step closer because now both ordered_length and field_cut_length both equal the same values:

"length: 24.000m +/-15mm "

So it looks like it missed the first 'm' ...

wow, i didn't expect this to be so hard, but definately my 'greenness in the syntax' has not helped me at all .. :(

Marioth
22nd June 2007, 19:30
This from the manual from BaaN, hopes it helps.

long STRING.SCAN( str_expr, string format(.) [, variable, ...] )
This function scans the given string expression str_expr using the
format string. The values found in the string expression are placed in
the specified variables. Conversion symbols should be stated in the
format string at the position where an expression is expected. The
function scans the string expression as long as characters belongs to
the given format, or until a separator is found. For example, in case of
conversion symbol %d, the system keeps reading until a non-digit is
encountered. The following conversion symbols can be used:

%s for (multibyte) strings
%f for doubles
%d for longs

A separator should be always one unique character. Make sure that the
separator is not used in another string in the string expression.
If more than one separator characters are placed between two conversion
symbols they are ignored unless they are matching with the input.
Note that scanning of the argument stops if the input character mathes
with the first expecting separator character.

This function is able to scan multibyte characters. This only applies to
the input string. The function doesn't allow the use of multibyte
characters as separators in the format string. The function returns the
number of scanned fields.

Examples:
double D
long L
string S(80)
long ret

ret = string.scan("string 123 456.78","%s %d %f",S,L,D)
| S contains "string", L contains 123, D contains 456.78

ret = string.scan("string|123|456.78","%s|%d|%f",S,L,D)
| S contains "string", L contains 123, D contains 456.78

metropoj
22nd June 2007, 20:22
yeah, I read that about 10 times and what was suggested should work according the that, as %s should be my string ...

hey, I see what you mean, says it should be a unique character. With that, I grabbed the ':' instead, now the field_cut_length = the first 15 characters of the string, not the first 15 after the ':' LOL Man .....

Still at it ....

metropoj
22nd June 2007, 20:47
Finally I understand this !

I had to make a bunch of declaration variables and basically break up the string into little chunks and only look at the chunks I want to ... man, clear as mud ...

So, final working sol'n was :


string.scan(ordered_length(1,1)," %s:%sm%s",field_cut_length(1,1),field_cut_length2(1,1),field_cut_length3(1,1))



That grabs FCL = Length
FCL2 = 24.0000
FCL3 = +/-15mm.

Boy, seems so simple now that I get it :) ...

Thanks for the help and hints !!!!!

Much appreciated ....