begincsdn .NET 趴趴窝
[天行健,君子以自强不息]
[天道酬勤思]

字符串比较是否相同,在编程过程中是很常见的,对于定长的字符串比较,如果字符串比较的还相当频繁,可以用下面的方法优化,但在实际编程时,如果效率不是问题时,请不要使用该方法,影响别人阅读,同时软件的维护难度也会加大。

 

 

char * source = "xyZ";
  int target = (((int)'Z')<<16) + (((int)'y')<<8) + (((int)'x')); //‘Z’在高字节位,‘x’在低字符位
  int svalue = ((int*) source)[0];
  cout << target << " " << svalue << endl;
posted on 2012-07-19 16:36  begincsdn  阅读(1555)  评论(0编辑  收藏  举报