[英]In Delphi is there a double quote string function?
I'm aware of the QuotedStr
function, but is there a similar function for double quoting for example 我知道
QuotedStr
函数,但是有一个类似的函数用于双引号
for i := 0 to List.count - 1 do
begin
List[i] := DoubleQuotedStr(List[i]);
end;
You can use AnsiQuotedStr
which accepts a quote character: 您可以使用接受引号字符的
AnsiQuotedStr
:
List[i] := AnsiQuotedStr(List[i], '"');
From the documentation : 从文档 :
function AnsiQuotedStr(const S: string; Quote: Char): string;
....
....
Use AnsiQuotedStr to convert a string (S) to a quoted string, using the provided Quote character.
使用AnsiQuotedStr将字符串(S)转换为带引号的字符串,使用提供的Quote字符。 A Quote character is inserted at the beginning and end of S, and each Quote character in the string is doubled.
在S的开头和结尾插入一个引号字符,并且字符串中的每个引号字符都加倍。
In the newer Delphi versions, if you include System.SysUtils
, you can use the string helper function TStringHelper.QuotedString with parameter '"'
: 在较新的Delphi版本中,如果包含
System.SysUtils
,则可以使用字符串辅助函数TStringHelper.QuotedString和参数'"'
:
'Test'.QuotedString('"')
This will return "Test"
. 这将返回
"Test"
。
I made a small unit test for it: 我做了一个小单元测试:
uses
System.SysUtils, DUnitX.TestFramework;
(...)
procedure TStringFunctionsTests.TestWithQuotedString;
var
TestString: string;
ExpectedResult: string;
TestResult: string;
begin
TestString := 'ABC';
ExpectedResult := '"ABC"';
TestResult := TestString.QuotedString('"');
Assert.AreEqual(TestResult, ExpectedResult);
end;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.