Removing '#$A' from Delphi string
Solution 1
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.
Solution 2
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.
Related videos on Youtube
JCTLK
I am a Software engineer and mainly into C#. Also interested in SQL server and it's applications.
Updated on July 09, 2022Comments
-
JCTLK almost 2 years
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
-
David Heffernan almost 13 yearsYou might want to consider removing
#$D
too while you are at it.
-
-
JCTLK almost 13 yearsThanks alot... I will mark this correct tomorrow.coz gotta leave now.
-
PA. almost 13 years@Andreas, I totally agree that this is a very good answer absolutelly deserving to be accepted. But, in general it is a good idea and it is SO good practice, too, just wait some longer to see if a simpler, more complete, better explained answer is posted.
-
JCTLK almost 13 yearsYep.. I was in a rush to leave.Therefore didn't have 5 mins to mark this. So I have done today.. Thanks alot. @Andreas : I guess this answers your question. :)