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.
Ugh, C++ .net, makes me sad each time I see someone using it. You'd probably have better luck posting at a .net forum since .net doesn't use any standard C and C++ libraries. Why are you mixing .Net and C++ libraries, you might as well use either String or std::string (not .net).
std::wostringstream integer; // why name this integer, only makes this confusing
Why are you using BinarySearch() what does that do, why not just recurse through the list and see if the string exists.
.Net String is always using wide-character so this is redundant:
Yeah, I realised BinarySearch wasn't what I was looking for a while after I posted :S
Unfortunately, after trying for the last couple of hours, I can't work out how to just go through the list checking to see if it contains the generated string. Any pointers?
Rather than storing a pointer (which I assume ^ is by the syntax you are using) store it as the list as the actual variable.
List<String> list;
I'm not sure how different it is from C++, or I should say how similar it is C++ as compared to something like C#. If you are storing a pointer in the list I would assume if you did any type of built-in search it would be comparing pointers so it will always return -1 since it'd never be the same pointer.
By the sounds of it you should be able to use BinarySearch() from what I read, perhaps you could try Contains() as well. Again you'd need to make sure that it's checking the actual value and not a pointer.