robertvg
20th June 2007, 11:52
This might be an easy one, but I'm probably overlooking something.
I'm trying to convert a string to a string limited to a max of 9 positions.
If the input string is smaller the full string should be returned, if the input string is larger, lets say 10 positions, then the first position should be cut of instead of the last positions.
I expected that sprint$("%-.9s", input.string) would do it, but it cuts of the last character.

Somebody any idea ?

Thanks in advance,
Robert

günther
20th June 2007, 13:03
Hi Robert,

I think the problem is that %*.*s and its pendants always start from the first character. Here is my workaround:

sprintf$("%-.9s", len(strip$(input.string)) <= 9) ? input.string : input.string(len(strip$(input.string)) - 9; 9) ) )

Günther

en@frrom
20th June 2007, 14:28
Günther's suggestion should work (except for some misplaced '(' and ')', and len - 9 instead of len - 8), however why is the sprintf$ necessary? I think you could just write:
if len(strip$(shiftl$(input.string))) <= 9 then
input.string = input.string(len(strip$(shiftl$(input.string))) - 8; 9)
endif

Am I missing something...?

Regards,
Eli Nager

robertvg
20th June 2007, 15:18
You are not missing something - I now implemented it more or less the same.
It was more a matter of trying to find the most efficient coding.