I am modifying a delphi app.In it I'm getting a text from a combo box. The problem is 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With