wxWidgets, C++, VS2010
I have a wxString that contains the displayed text from a non-static web page (using wxWebView & GetSelectedText())
I need to process this string, character by character, in order to extract certain information from certain locations based on the surrounding characters.
wxString is Unicode (& sometimes UTF8) though so this doesn't work well in a loop getting each character in turn.
So, how can I convert from wxString, into an ASCII char array, 1 byte per character? (and also know the length of this array)
I'm aware that this would be a 'lossy' process, I'm happy with that as I'm only looking for text that is ASCII.
It does work perfectly well in a loop, wxString::operator[]
returns you the character (well, ignoring surrogate complications under Windows) at the given index, not the byte, even if the string is represented internally as UTF-8. Of course, this also means that it can't be implemented efficiently, so the preferred way to iterate over the string is:
for ( wxString::const_iterator it = s.begin(); it != s.end(); ++it ) {
wchar_t wch = *it;
... do whatever you need with wch ...
}