Created On: 23 February 2011
Problem:
If you have a .Net string that is padded at the end with null (x"00") characters how can you remove these from the string ?
Resolution:
The .Net method TrimEnd from the System.String class allows you to do this. You need to supply an array of characters to the method that tells it what characters to strip.
In Visual COBOL an example piece of code that does this is:-
program-id. Program1 as "TrimNulls.Program1". data division. working-storage section. 01 ws-string-with-nulls. 03 filler pic x(4) value "Test". 03 filler pic x(16) value all x"00". 01 ws-string string. *> .Net String Type
In Visual COBOL an example piece of code that does this is:-
program-id. Program1 as "TrimNulls.Program1". data division. working-storage section. 01 ws-string-with-nulls. 03 filler pic x(4) value "Test". 03 filler pic x(16) value all x"00". 01 ws-string string. *> .Net String Type
01 ws-nulls character occurs 1 value (0). *> Array (1 element) of chars (null).
procedure division.
set ws-string to ws-string-with-nulls display ws-string " is of length " ws-string::Length *> Display length of string
display "Trimming String ....." set ws-string to ws-string::TrimEnd(ws-nulls) *> Trim expects an array of characters to strip
display ws-string " is of length " ws-string::Length *> Display length of string
goback. end program Program1.