开发者

Removing '#$A' from Delphi string

I am modifying a delphi app.In it I'm getting a text from a combo box. The problem i开发者_开发百科s that when I save the text in the table, it contains a carriage return. In debug mode it shows like this.

newStr := 'Projector Ex320u-st Short Throw '#$A'1024 X 768 2700lm'

Then I have put

newStr := StringReplace(newStr,'#$A','',[rfReplaceAll]);

to remove the '#$A' thing. But this doesn't remove it.

Is there any other way to do this..

Thanks


Remove the quotes around the #$A:

newStr := StringReplace(newStr,#$A,'',[rfReplaceAll]);

The # tells delphi that you are specifying a character by its numerical code. The $ says you are specifying in Hexadecimal. The A is the value.

With the quotes you are searching for the presence of the #$A characters in the string, which aren't found, so nothing is replaced.


Adapted from http://www.delphipages.com/forum/showthread.php?t=195756

The '#' denotes an ASCII character followed by a byte value (0..255).

The $A is hexadecimal which equals 10 and $D is hexadecimal which equals 13.

#$A and #$D (or #10 and #13) are ASCII line feed and carriage return characters respectively.

Line feed = ASCII character $A (hex) or 10 (dec): #$A or #10

Carriage return = ASCII character $D (hex) or 13 (dec): #$D or #13

So if you wanted to add 'Ok' and another line:

Memo.Lines.Add('Ok' + #13#10)

or

Memo.Lines.Add('Ok' + #$D#$A)

To remove the control characters (and white spaces) from the beginning and end of a string:

MyString := Trim(MyString)

Why doesn't Pos() find them?

That is how Delphi displays control characters to you, if you were to do Pos(#13, MyString) or Pos(#10, MyString) then it would return the position.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜