Jump to content


This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.
Photo

Howto init a string?


1 reply to this topic

gronchi

gronchi
  • Members
  • 71 posts

Posted 19 December 2002 - 11:21

Hi to all,
I'm not an expert programmer and I have a little problem.
I have a file each row it's a text string of two types:
name or <name>
I want to remove brackets (< and > signs). See pseudocode:

Input:
<LOWERLAYERS>
<PLATFORM>
<USM>
<LOADFILES>

Output I expect:
LOWERLAYERS
PLATFORM
USM
LOADFILES

------
Case 1.
------
Code Sample

while (...) // end of file ...
 GetLine (nvFileHandle, svLine);
 // remove (if any) the "<" and ">"
 i = j = 0;
 while i < StrLength(svLine)
    if ((svLine[i] != '<') && (svLine[i] != '>')) then
       svLineBis[j] = svLine[i];
       j++;
    endif;
    i++;
 endwhile;
 WriteLine (nvFileHandle, szLineBis);
endwhile;


Output:
LOWERLAYERS
LOWERLAYERSPLATFORM
LOWERLAYERSPLATFORMUSM
LOWERLAYERSPLATFORMUSMLOADFILES

My Comment:
svLineBis string was not cleaned up and it write at the end of the previous writing.


------
Case 2. (I try to init the string but...)
------
Code Sample

while (...) // end of file ...
 svLineBis = ""; // INIT ???
 GetLine (nvFileHandle, svLine);
 // remove (if any) the "<" and ">"
 i = j = 0;
 while i < StrLength(svLine)
    if ((svLine[i] != '<') && (svLine[i] != '>')) then
       svLineBis[j] = svLine[i];
       j++;
    endif;
    i++;
 endwhile;
 WriteLine (nvFileHandle, szLineBis);
endwhile;


Output:
LOWERLAYERS




My Comment:
Where are the other lines?


------
Case 3. another way...
------
Code Sample

while (...) // end of file ...
 GetLine (nvFileHandle, svLine);
 // remove (if any) the "<" and ">", another way...
 CopyBytes (svLineBis, 0, svLine, 1, (StrLength(svLine)-2));
 WriteLine (nvFileHandle, szLineBis);
endwhile;


Output:
LOWERLAYERS
PLATFORMERS
USMTFORMERS
LOADFILESRS

My Comment:
svLineBis string was not cleaned up


------
Case 4. another way with the same string initi
------
Code Sample

while (...) // end of file ...
 svLineBis = ""; // INIT ???
 GetLine (nvFileHandle, svLine);
 // remove (if any) the "<" and ">", another way...
 CopyBytes (svLineBis, 0, svLine, 1, (StrLength(svLine)-2));
 WriteLine (nvFileHandle, szLineBis);
endwhile;


Output:
LOWERLAYERS
PLATFORMERS
USMTFORMERS
LOADFILESRS

My Comment:
the same...


Conclusion
I guess all my problems are I'm not understand the right way to init a string.
Anyone can help me?


Thanks.
Ciao, Giuseppe

probsar

probsar
  • Members
  • 31 posts

Posted 19 December 2002 - 13:04

You have to clean your "svLineBis" Variable after each WriteLine Command with e.g. svLineBis = "";

Code Sample

[B]svLineBis = "";[/B]
while (...) // end of file ...
GetLine (nvFileHandle, svLine);
// remove (if any) the "<" and ">"
i = j = 0;
while i < StrLength(svLine)
   if ((svLine[i] != '<') && (svLine[i] != '>')) then
      svLineBis[j] = svLine[i];
      j++;
   endif;
   i++;
endwhile;
WriteLine (nvFileHandle, szLineBis);

[B]svLineBis = "";[/B]

endwhile;