Page 1 of 1 1
Topic Options
#123935 - 2004-07-26 05:35 PM Need some string expertise here ...
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
actually I am writing on a tool to export/import groups/users/policies etc. for the new project I am part of (some kind of test center).

I build an array of groups from a file created by the obvious tools the following (simplified) way:

Code:

->loop
-> readline
-> if instr(line,"*")
-> string = string + right(line,-1) + chr(10)
-> endif
->/loop
string = left(string,-1) ;strip last chr(10)
array = split(string,chr(10))



in this szenario (3200+ groups) the string grows over 32000 characters in length, no problem!
From the array i build then an ini file with the elements as sections containing the group's descriptions as keys.

Now the problems start. On importing I do a readprofilestring on the sections of this ini file like:

Code:

string = readprofilestring(ini,"","")
string = left(string,-1) , strip last chr(10)
array = split(string,chr(10))



One should think that this works too as the both strings should contain the same data, but the 32000 character limit seems to apply only to readprofilestring as this craps out with 'Expression too long'; Which I kinda can't accept as the first way of creation works ok

Is there any known workaround to this ?

My other option would be to split the ini file in parts of 1600 sections per file, which I consider a pain
_________________________



Top
#123936 - 2004-07-26 07:20 PM Re: Need some string expertise here ...
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
What happens if you skip the string part and go straight to an array?

$Array = Split(ReadProfileString('file.ini','',''),CHR(10))

Then just ReDim to lose the last element.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#123937 - 2004-07-26 07:26 PM Re: Need some string expertise here ...
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Yap,

tried that already, sorry that I forgot to mention
It's obviously not that trivial as the string (readprofilestring) has to be created before it can be split ... the right to left order principle

What really stumped me is that I can actually create a string variable over 32000 chars long with 'cumulation' (see first part)

Mmmaybe I should, go with the splitted ini files
_________________________



Top
#123938 - 2004-07-27 11:30 AM Re: Need some string expertise here ...
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Ok, I accepted the fact that readprofilestring() can't create strings over 32000 chars, so I decided to split the ini files to parts of 1600 groups per file (1600 * 20 (max group chars) = 32000) like this :

creation :

Code:
$_ = writeprofilestring($sTargetFolder + '\grp\grp' + $c/1600 + '.ini',$item,"Desc",$a)



where $c is a passed for-next counter

readout :

Code:
        dim $a, $c

$c = 0
while exist($sTargetFolder + '\grp\grp' + $c + '.ini')
$a = $a + readprofilestring($sTargetFolder + '\grp\grp' + $c + '.ini','','') + chr(10)
$c = $c + 1
loop
$a = left($a,-1)
$Enum_GRP = split($a,chr(10))




this works ok, allthough the string grows over 32000 chars in length

Now, as I tested this in a German environment where domain equals Domäne, I have lost some groups during export as a shelled net group command seems to deny working with 'umlauts' [äöü] (do you have a word for this in English ?) ...

the following line fails (ASCII is ON):

Code:
shell '%ComSpec% /c net group "' + $item + '" /domain > "' + $tmpfile + '" 2>nul'



where $item = 'Domänen-Admins' or something similar...
On the other side typing the command at command prompt works ok

Any insight there ?
thanx in advance


Edited by Jochen (2004-07-27 11:31 AM)
_________________________



Top
#123939 - 2004-07-27 11:59 AM Re: Need some string expertise here ...
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11631
Loc: CA
Can you substitute the ä in 'Domänen-Admins' with the CHR(196) code?

Top
#123940 - 2004-07-27 12:16 PM Re: Need some string expertise here ...
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
looks promising ... works in test.

need to convert on runtime though, will let you know.

Thanx
_________________________



Top
#123941 - 2004-07-27 02:09 PM Re: Need some string expertise here ...
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
quite a pain but no significant slowdown as there are (normally) only 3 groups that match the condition :

Code:
    if instr($item,'ä')
while instr($item,'ä')
$item = left($item,instr($item,'ä')-1) + chr(196) + right($item,len($item)-instr($item,'ä'))
loop
endif
if instr($item,'ö')
while instr($item,'ö')
$item = left($item,instr($item,'ö')-1) + chr(214) + right($item,len($item)-instr($item,'ö'))
loop
endif
if instr($item,'ü')
while instr($item,'ü')
$item = left($item,instr($item,'ü')-1) + chr(220) + right($item,len($item)-instr($item,'ü'))
loop
endif



Thanx Ron for the tip my friend
_________________________



Top
Page 1 of 1 1


Moderator:  Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 764 anonymous users online.
Newest Members
ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder, M_Moore
17887 Registered Users

Generated in 0.137 seconds in which 0.069 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org