spartacus
26th October 2011, 15:21
Hello,
once more I have a problem with the Baan string.scan()-Function.
The string I want to split is: (contains also spaces)
string.variable = "123 %cd% ef"
The %-signs should be the separator.
How can I split this with string.scan() into three parts?
:( I tried a lot but 'til now nothing works.
Kind regards
Richard
zardoz
26th October 2011, 15:34
IMHO the problem is in the string separator you want to use. The % character is used also to define the kind of field in the second argument of string.scan.
The syntax could be :
string.scan$(string.variable, "%s%%s%%s", a, b, c)
where the % rapresents the separator, but the % is also used for define the type, so isn't clear what format must have the format argument.
Maybe putting a double % as separator ("%s%%%s%%%s")?
spartacus
26th October 2011, 15:58
Hi Zardoz,
thanks for the quick reply. I know about the special functionality if the "%-"sign in string.scan().
I tried already both variants you proposed me to try... without success.
OK maybe I misstyped something....
If someone can give me a syntax which works for sure, I will try it once more. In the meantime I will write a loop and separate ist myself. But to find a solution with string.scan() will be much more satisfying.
Kind regards
Richard
vahdani
26th October 2011, 16:38
Hi richard,
I don't know if there is any "correct" syntax. This helps in any case:):
function main()
{
string string.variable(100)
long ret
long number.of.fields
string a(10)
string b(10)
string c(10)
string format$(20)
string.variable = "123 %cd% ef"
format$ = "%s|%s|%s"
while true
ret = pos(string.variable, "%")
if ret = 0 then
break
endif
string.variable(ret;1) = "|"
endwhile
number.of.fields = string.scan(string.variable, format$ , a, b, c)
}
spartacus
26th October 2011, 16:55
Hi vahdani,
thanks for your support! I also had your solution in mind. But because it is possible, that the string can be wasted with any kind of characters, except the "%"-sign I can't use it without risk.
Kind regards
Richard
mark_h
26th October 2011, 19:01
Spartacus,
His little script will work - just take it one step farther. Instead if using a printable character - use something like ESC or STX. This worked for me:
string.variable = "123 %cd% ef"
format$ = "%s"&chr$(27)&"%s"&chr$(27)&"%s"
while true
ret = pos(string.variable, "%")
if ret = 0 then
break
endif
string.variable(ret;1) = chr$(27)
endwhile
number.of.fields = string.scan(string.variable, format$ , a, b, c)
JaapJD
26th October 2011, 21:31
If you have to 'repair' the string before you can scan it, I would write the string.scan myself:
string string.variable(100)
long i, j, k
string s(10,10)
string.variable = "123 %cd% ef"
set.mem(s, "")
j = 1
k = 1
for i = 1 to len(string.variable)
if string.variable(i;1) = "%" then
k = k + 1
j = 1
else
s(j, k) = string.variable(i;1)
j = j + 1
endif
endfor
spartacus
27th October 2011, 14:23
Hi all,
thank you, for your support!
As already written at the beginning: I scan the string myself. I stopped all other tries.
It is a little anoying that there is now way with string.scan(), but life goes on!
Kind regards
Richard