Skip to main content

Posts

Showing posts from October, 2012

Android - Disable Text Selection

In order to disable text selection in a WebView we can use following approaches: CSS * {   user-select: none; -moz-user-select: -moz-none; -khtml-user-select: none; -webkit-user-select: none; } This approach will not work on all the versions of Android as the support was not there till late. Handling LongClick public void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);     setContentView(R.layout.activity_main);     WebView webView = (WebView) this.findViewById(R.id.webView1);     webView.loadData("<html><head><style>head><body>You scored           <b>192</b>     points.</body></html>", "text/html", null);                     webView.setOnLongClickListener(new View.OnLongClickListener() {         public boolean onLongClick(View v) {              return true;         }     }); }

Split String in C++ with delimiters

In order to split string in c++ we can use strtok(). A sequence of calls to this function split str into tokens, which are sequences of contiguous characters separated by any of the characters that are part of delimiters. On a first call, the function expects a C string as argument for str, whose first character is used as the starting location to scan for tokens. In subsequent calls, the function expects a null pointer and uses the position right after the end of last token as the new starting location for scanning.  Read More Here #include <iostream.h> #include <string.h> int main( int argc, char ** argv) {      // multiple delimiters can be provided      char const delimiters[] = "/:" ;          // initial string to split        std::string sCFIString = "/6/2702!/4/6/6/122/1:3" ;          // this pointer will point to the next word after every 'strtok' call      char *token = strtok(const_cast< cha

Convert std::string to char* and const char* - c++

Convert std::string to const char* std :: string name = "Anuj" ; const char * constName = name.c_str(); Convert std::string to char* std :: string name = "Anuj" ; const char * constName = name.c_str(); char * ptrToName = const_cast< char *> (name.c_str()); A simple progam  #include <iostream> #include <stdio.h> using namespace std; int main() {     std :: string name = "Anuj" ;      const char * constName = name.c_str();      char * ptrToName = const_cast< char *> (name.c_str());     printf( "%s" ,constName);     printf( "%s" ,ptrToName);     cout << name << endl;      return 0 ; }