Question

I have a list in a CDATA element. How do I get the elements from the CDATA and add this to TStringList?

If I get the CDATA string, it returns:

'string'#10#9#9#9'string'#10#9#9#9'string'#10#9#9#9'string'...

However the characters #10#9#9#9 are not strings; I cannot use use the StringChangeEx method to replace these characters.

Thanks

Was it helpful?

Solution

The string you got is a valid notation for a string containing non printable characters. But you don't need to worry that you lose any char when working with a string list or the StringChangeEx function. Let me convince you with this short script:

[Code]
const
  PrintableString = 'string-string-string-string';
  NonPrintableString = 'string'#10#9#9#9'string'#10#9#9#9'string'#10#9#9#9'string';

procedure InitializeWizard;
var
  S: string;
  StringList: TstringList;
begin
  StringList := TstringList.Create;
  try
    StringList.Add(NonPrintableString);
    S := StringList[0];

    if S = NonPrintableString then
      MsgBox('String list didn''t lose non printable chars!', mbInformation, MB_OK);

    StringChangeEx(S, #10#9#9#9, '-', True);

    if S = PrintableString then
      MsgBox('String has been modified as expected!', mbInformation, MB_OK);
  finally
    StringList.Free;
  end;
end;

However, I think your question has been raised just because you want to present these data to the user, and that might be sometimes difficult with non printable chars. One example for all. If you'll have a string which contains a null terminator in the middle and you will want to show such string to the user, e.g. in a message box, you'll get displayed only the part of that string which is before that terminator. But, it's not something you can affect. That's just how the Windows API function call which is behind treats the string:

[Code]
procedure InitializeWizard;
var
  S: string;
begin
  S := 'Hello'#0' world!';
  MsgBox(S, mbInformation, MB_OK);
end;

As you can see, for the above case would be necessary to replace the null terminator char with some printable char, e.g. space.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top