Weary from translating the works of Stephen King into Latin, Bob said:
MQ> My experience with this was with a variable defined in a TYPE
MQ> statement. To verify my past results I wrote a NEW test program as
MQ> follows:
MQ> TYPE test
MQ> a as STRING * 10
MQ> END TYPE
JG> Ok, this is what you will learn from this venture... Strings are null
JG> padded when defined in TYPE structures and the actual data length is
JG> less than the defined length.
JG> Hence, you now see why your rtrim$(variable) does not work, because
JG> this function without additional parameters defaults to stripping a
JG> space, ascii 32, and not a null, ascii 0.
JG> Hence, rtrim$(variable, any chr$(0)+" ") takes BOTH into
JG> consideration, and also bear in mind there is more than 1 way of
JG> expressing this (see
JG> other examples.)
In this case, Quintin is correct, and you are not. A
fixed-length string variable, whether DIMmed or TYPEd, will
always be that length and padded on the right with nulls.
Therefore, while rtrim$ will strip the nulls out of a
fixed-length string, if you place the results back into a
fixed-length string, that will then be padded on the right
with nulls. So, the following code:
dim c as string * 10
c = "12345"
print "[" + c + "]"
c = rtrim$(c)
print "[" + c + "]"
c = rtrim$(c, chr$(0))
print "[" + c + "]"
b$ = rtrim$(c, chr$(0))
print "[" + b$ + "]"
...produces the following screen output:
[12345 ]
[12345 ]
[12345 ]
[12345]
The first line is the original contents of c, padded onm
the right with nulls. The second line is the contents of c
after a regular rtrim$ using the default of only stripping
spaces. As you said, the nulls are still there. The third
line shows your error, in that, while rtrim$ did its job of
stripping the nulls, PowerBASIC then put the resuling
5-character string back into a 10-character-length
fixed-length string, and padded it with nulls. The fourth
result is what you expected to happen, i.e., the result of
rtrim$ was placed into a variable-length string, which
doesn't put the nulls in.
... Is fearr go mall n go br ch!
--- PPoint 1.96
---------------
* Origin: Seven Wells On-Line * Nashville, TN (1:116/3000.12)
|