3
我有兩個字符串,我需要比較兩個字符串是否相等。Delphi中的字符串比較
串1以這種方式創建的:
var
inBuf: array[0..IN_BUF_SIZE] of WideChar;
stringBuilder : TStringBuilder;
mystring1:string;
...
begin
stringBuilder := TStringBuilder.Create;
for i := startOfInterestingPart to endOfInterestingPart do
begin
stringBuilder.Append(inBuf[i]);
end;
mystring1 := stringBuilder.ToString();
stringBuilder.Free;
字符串2是一個常數字符串'ABC'
。
當字符串1顯示在調試控制檯中時,它等於'ABC'。但比較
AnsiCompareText(mystring1, 'ABC')
mystring1 = 'ABC'
CompareStr(mystring1, 'ABC')
所有報告的不平等。
我想,我需要轉換字符串2('ABC'
)同一類型爲字符串1
我怎麼能這樣做?
更新2012年9月26日:
aMessage
顯示在日誌輸出爲{FDI-MSG-START-INIT-FDI-MSG-END}
下面是用於打印的長度的碼字符串:
StringToWideChar('{FDI-MSG-START-Init-FDI-MSG-END}', convString, iNewSize);
...
OutputDebugString(PChar('Len (aMessage): ' + IntToStr(Length(aMessage))));
OutputDebugString(PChar('Len (original constant): ' + IntToStr(Length('{FDI-MSG-START-Init-FDI-MSG-END}'))));
OutputDebugString(PChar('Len (convString): ' + IntToStr(Length(convString))));
而這裏的日誌輸出:
[3580] Len (aMessage): 40
[3580] Len (original constant): 32
[3580] Len (convString): 0
1)什麼是mystring.length? 2)如果長度相同 - 做一個循環,通過字符char,哪些字符是相同的,什麼時候是不同的。 3)如果/當發現不同的字符時,比較兩個字符串的Word(char)。 我猜你明白「ABC」和「АВС」沒有單一的普通字母。 –
*將字符串2('ABC')轉換爲與字符串1 *相同的類型 - 我在此看不需要,但是如果您堅持 - * var mystring1,mystring2:string; ... mystring2:='ABC'; * –
* AnsiCompareText(aMessage,'ABC')*你有什麼比較? aMessage或mystring1? –