(50分)关于StringBuilder.ToString()的怪问题
我有如下代码:
public ProcessedDocument Discarding_NonArabic_Letters(string[] savedSeparators,string notAllArabic)
{
string[] splittedStrings = notAllArabic.Split(savedSeparators, StringSplitOptions.RemoveEmptyEntries);
ProcessedDocument allArabicPD;
ArabicLettersStruct ar = ArabicLetters();
Char[] arabicLettersArray = ar.arabicLettersArray;
String arabicLettersString = ar.arabicLettersStringWithSpace;
StringBuilder result = new StringBuilder();
foreach (string ss in splittedStrings)
{ foreach (Char c in ss.ToCharArray())
{
if (arabicLettersString.IndexOf(c) > = 0)
{
result.Append(c);
}
}
result.Append(savedSeparators[0].ToString());
}
allArabicPD = new ProcessedDocument(result.ToString());
//contains only Arabic letters + special separator
return TrimExtraSpaces(allArabicPD);
}
==================================================
假如有这个值 savedSeparators[0] = "C: "
这个语句result.Append(savedSeparators[0].ToString());正常执行后,
能正确添加 "C: " 给result.
但这条语句allArabicPD = new ProcessedDocument(result.ToString()); 执行后,
result变量中的 "C: " 变成了 "C ",丢失了“:”???
类似的情况,
假如有这个值 savedSeparators[0] = "C:\ "
这个语句result.Append(savedSeparators[0].ToString());正常执行后,
能正确添加 "C:\ " 给result.
但这条语句allArabicPD = new ProcessedDocument(result.ToString()); 执行后,
result变量中的 "C:\ " 却变成了 "C\\ " ???
请问是什么原因呢?怎样解决这个奇怪的问题?
------解决方案--------------------要看你ProcessedDocumentd的构造函数...