Hi,
I want to search a managed list, List<String^>^ list, for a variable substring (i.e. the substring changes it's contents every time it is looped).
The list is populated by a Unicode (UTF-16LE) text file. The substring to be searched for is basically an ID for the Strings that occurs at the beginning of each String (the second half of the string is unknown), so I loop through and search the List for a different ID each time (i.e. IDS_STRING1, IDS_STRING2 etc.) The idea being that if it doesn't yet exist, I write it to file.
I can declare the List and store the file in it no problem, but when it comes to searching this managed list for a managed substring, I just can't seem to figure it out. What is the best method to use?
Here's my code so far (but remember, I don't know how to search for the substring, so I don't think my method is correct):
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"\t";
wstring thisString = integer.str();
String^ SpareString = gcnew String (thisString.c_str());
bool index = load->StartsWith(SpareString); //I know it's not StartsWith, this is just me putting something in to identify what needs doing
System::IO::StreamWriter^ WriteSpareStrings = gcnew System::IO::StreamWriter(L"Chinese.txt", true, System::Text::Encoding::Unicode);
if(index == false)
{
WriteSpareStrings->Write(SpareString + L"\"Spare String\"");
WriteSpareStrings->Write(L"\r\n");
}
WriteSpareStrings->Flush();
WriteSpareStrings->Close();
}
The other thing to note is that when I do the search it has to include the tab after the IDS_STRING# as I don't want to find IDS_STRING30 for IDS_STRING3 or something like that.
Any insight would be greatly appreciated, thank you.