[英]Removing '#$A' from Delphi string
I am modifying a delphi app.In it I'm getting a text from a combo box. 我正在修改delphi app.In它我从组合框中获取文本。 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. 删除'#$ A'的东西。 But this doesn't remove it.
但这并没有消除它。
Is there any other way to do this.. 有没有其他方法可以做到这一点..
Thanks 谢谢
Remove the quotes around the #$A: 删除#$ A周围的引号:
newStr := StringReplace(newStr,#$A,'',[rfReplaceAll]);
The # tells delphi that you are specifying a character by its numerical code. #告诉delphi你用数字代码指定一个字符。 The $ says you are specifying in Hexadecimal.
$表示你用十六进制指定。 The A is the value.
A是价值。
With the quotes you are searching for the presence of the #$A characters in the string, which aren't found, so nothing is replaced. 使用引号,您正在搜索字符串中#$ A字符的存在,这些字符未找到,因此不会替换任何内容。
Adapted from http://www.delphipages.com/forum/showthread.php?t=195756 改编自http://www.delphipages.com/forum/showthread.php?t=195756
The '#' denotes an ASCII character followed by a byte value (0..255). '#'表示ASCII字符,后跟字节值(0..255)。
The $A
is hexadecimal which equals 10
and $D
is hexadecimal which equals 13
. $A
是十六进制,等于10
, $D
是十六进制,等于13
。
#$A
and #$D
(or #10
and #13
) are ASCII line feed and carriage return characters respectively. #$A
和#$D
(或#10
和#13
)分别是ASCII换行符和回车符。
Line feed = ASCII character $A
(hex) or 10
(dec): #$A
or #10
换行= ASCII字符
$A
(十六进制)或10
(十进制): #$A
或#10
Carriage return = ASCII character $D
(hex) or 13
(dec): #$D
or #13
回车符= ASCII字符
$D
(十六进制)或13
(十进制): #$D
或#13
So if you wanted to add 'Ok' and another line: 所以如果你想添加'Ok'和另一行:
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? 为什么Pos()找不到它们?
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. 这就是Delphi如何向你显示控制字符,如果你要做
Pos(#13, MyString)
或Pos(#10, MyString)
那么它会返回位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.