Jump to content
  • Advertisement
Sign in to follow this  
jsloan

std::string and Unicode problem

This topic is 5034 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is it possible that std::string find() function will not recognize certain characters? For example:
std::string test = "☺VERSION☺";

int result = test.find("☺");

//result always equals (-1) meaning it didnt find it


ok its formatting it into some WEIRD garbage here on the board, buts its a small smiley face type character.... thanks

Share this post


Link to post
Share on other sites
Advertisement
Are you sure your giving us the exact code as above because this works:


#include <string>
#include <iostream>

int main() {

std::string test("&#9786;VERSION&#9786;"), key("&#9786;");

std::string::size_type result = test.find(key);

if(result != std::string::npos)
std::cout << "found at pos: " << result << ", word: " << test.substr(result, key.length()) << std::endl;
else
std::cout << "Not found" << std::endl;

return 0;

}



All of those characters are in ascii character set, you don't need wstring unless you are going to use wide characters but i don't see that being the case.

Share this post


Link to post
Share on other sites
@snk_kid:
He's not trying to search for any of the characters in the ASCII string "&#9786;". He's trying to search for the UNICODE character ☺, who's HTML entity is "&#9786;". He formatted it that way for this forum.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!