Hey,
I'm trying to search a List for a substring, but even if it does exist the result is coming out as negative (not present) using the BinarySearch.
The idea is that once the file has been loaded into the list I search to see if substrings exist (i.e. IDS_STRING1 ) <-- includes tab. The lines in the file will say "IDS_STRING# "Something else written after tab"", but as anything could be written after the tab, that's why I need to search for the first part of the string only.
The text file is in Unicode (UTF-16 LE).
Can anyone see what I'm doing wrong in the code below? Sorry if it's really obvious, but I just can't see it.
List<String^>^ load = gcnew List<String^>();
// load file
{
System::IO::StreamReader^ sr = gcnew System::IO::StreamReader(L"Chinese.txt",System::Text::Encoding::Unicode,true);
String^ line1;
while((line1 = sr->ReadLine()) !=nullptr)
{
load->Add(line1);
}
sr->Close();
load->Sort();
}
// output to file
for(int i = 1; i < 1018; ++i)
{
std::wostringstream integer;
integer << L"IDS_STRING" << i << L"\x09";
wstring thisString = integer.str();
String^ SpareString = gcnew String (thisString.c_str());
int index = load->BinarySearch(SpareString);
System::IO::StreamWriter^ WriteSpareStrings = gcnew System::IO::StreamWriter(L"Chinese.txt", true, System::Text::Encoding::Unicode);
if(index < 0)
{
WriteSpareStrings->Write(SpareString + L"\"Spare String\"");
WriteSpareStrings->Write(L"\r\n");
}
WriteSpareStrings->Flush();
WriteSpareStrings->Close();
}
Thanks!