【发布时间】:2014-09-06 12:03:01
【问题描述】:
我使用 Delphi 5 并从 http 连接中获得这样的字符串:
str :='content=bell=7'#$8'size=20'#$8'other1'#$D#$A#$8'other2'
这个字符串包含一些带有转义字符的序列,我想取消转义这些字符。如果我使用修剪功能,转义序列仍在里面。也许这是因为“#$8”不是可见的标志?
如何单独替换“#&8”。例如用'&',这样我就得到了字符串:
str1 :='content=bell=7&size=20&other1'#$D#$A'&other2'
在此之后,我可以使用 trim 取消转义其他序列。
str2 :='content=bell=7&size=20&other1#13#10&other2'
【问题讨论】:
-
如果 D5 有 StringReplace:
str1 := StringReplace(str, ''#$8'', '&', [rfReplaceAll]); -
第二个参数不需要引号:
str1 := StringReplace(str, #$8, '&', [rfReplaceAll]);
标签: string delphi escaping delphi-5