cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
jchristman
Pilgrim

Remove Spaces from string with Installscript

I am trying to remove spaces from a string using InstallScript. I try to use the StrReplace(svString," ","") which kinda works, but I have some strings that could have (" " )unknown number of spaces in the strings.

I was also looking from something that works like TRIM,LTRIM,RTRIM.
Labels (1)
0 Kudos
6 Replies
RobertDickau
Pilgrim

Re: Remove Spaces from string with Installscript

I haven't used them, but there seem to be some other approaches at www.installsite.org > InstallScript Samples > Strings.
0 Kudos
jchristman
Pilgrim

Re: Remove Spaces from string with Installscript

Thank your for the link.

I just finished this to strip out all spaces and tabs. here is what i used.

StrReplace(svFileLines,"\t","",0);
StrReplace(svFileLines," "," ",0);
\\ optional if the first two do not remove all empty space from a string.
CharReplace(svFileLines,STRTOCHAR('\0'),STRTOCHAR(''),0);
0 Kudos
TheTraveler
Pilgrim

Re: Remove Spaces from string with Installscript

Try these...

[CODE]
EXTERNAL prototype My_StrTrim(BYREF STRING, BYVAL STRING);
EXTERNAL prototype My_StrTrimLeft(BYREF STRING, BYVAL STRING);
EXTERNAL prototype My_StrTrimRight(BYREF STRING, BYVAL STRING);

///////////////////////////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////////////////////////
function My_StrTrimLeft(strDestination, strSource)
NUMBER nSize;
NUMBER nIndex;
BOOL bDone;
CHAR strChar;
begin
strDestination = strSource;
nSize = StrLength(strSource);
if nSize > 0 then
nIndex = 0;
bDone = FALSE;
while ( (!bDone) && (nIndex < nSize) )
strChar = strSource[nIndex];
if (strChar = " ") || (strChar = "\t") || (strChar = "\r") || (strChar = "\n") then
nIndex = nIndex + 1;
else
bDone = TRUE;
endif;
endwhile;

if (nIndex >= 1) && (nIndex < nSize) then
strDestination = "";
StrSub(strDestination, strSource, nIndex, nSize - nIndex);
elseif (nIndex >= nSize) then
strDestination = "";
endif;
endif;

return 0;
end;

///////////////////////////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////////////////////////
function My_StrTrimRight(strDestination, strSource)
NUMBER nSize;
NUMBER nIndex;
BOOL bDone;
CHAR strChar;
begin
strDestination = strSource;
nSize = StrLength(strSource);
if nSize > 0 then
nIndex = nSize - 1;
bDone = FALSE;
while ( (!bDone) && (nIndex > 0) )
strChar = strSource[nIndex];
if (strChar = " ") || (strChar = "\t") || (strChar = "\r") || (strChar = "\n") then
nIndex = nIndex - 1;
else
bDone = TRUE;
endif;
endwhile;

if (nIndex < (nSize - 1)) && (nIndex > 0) then
strDestination = "";
StrSub(strDestination, strSource, 0, nIndex + 1);
elseif nIndex < 0 then
strDestination = "";
endif;
endif;

return 0;
end;

///////////////////////////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////////////////////////
function My_StrTrim(strDestination, strSource)
STRING strTemp;
begin
strTemp = strSource;
My_StrTrimLeft(strTemp, strTemp);
My_StrTrimRight(strTemp, strTemp);
strDestination = strTemp;
end;
[/CODE]
0 Kudos
jchristman
Pilgrim

Re: Remove Spaces from string with Installscript

Thank you, this is perfect.

If you would not mind could you assist me with a couple other of my posts.

string parse/index error
http://community.macrovision.com/showthread.php?t=180356

XML and installscript
http://community.macrovision.com/showthread.php?t=180310
0 Kudos
TheTraveler
Pilgrim

Re: Remove Spaces from string with Installscript

Made some comments already... Take a look...
0 Kudos
jchristman
Pilgrim

Re: Remove Spaces from string with Installscript

Thank you. very much :)
0 Kudos