nsAString myString; // ... (initialize myString with contents) ... const PRUnichar* buffer = myString.BeginReading(); const char* cString = NS_ConvertUTF16toUTF8(buffer).get(); // now cString is a null-terminated string in UTF-8 encoding, which we can use in C-style APIs
nsAString myString; // ... (initialize myString with contents) ... const PRUnichar* buffer = myString.BeginReading(); size_t length = myString.Length(); const PRUnichar* found = wcsstr(buffer, L"needle"); if (found) { // the substring "needle" was found at position (found-buffer)! }Here we use `BeginReading()` to get a pointer to the buffer of an `nsAString`, and `Length()` to get its length. We then use `wcsstr()` to search for the `"needle"` substring in the buffer, and if it's found, we can calculate its position by subtracting `buffer` from the pointer returned by `wcsstr()`. Package/library: Mozilla Gecko browser engine