zoukankan      html  css  js  c++  java
  • strlen, wcslen, _mbslen, _mbslen_l, _mbstrlen, _mbstrlen_l, setlocale(LC_CTYPE, "Japanese_Japan")(MSDN的官方示例)

    // crt_strlen.c  
    // Determine the length of a string. For the multi-byte character  
    // example to work correctly, the Japanese language support for  
    // non-Unicode programs must be enabled by the operating system.  
      
    #include <string.h>  
    #include <locale.h>  
      
    int main()  
    {  
       char* str1 = "Count.";  
       wchar_t* wstr1 = L"Count.";  
       char * mbstr1;  
       char * locale_string;  
      
       // strlen gives the length of single-byte character string  
       printf("Length of '%s' : %d
    ", str1, strlen(str1) );  
      
       // wstrlen gives the length of a wide character string  
       wprintf(L"Length of '%s' : %d
    ", wstr1, wcslen(wstr1) );  
      
       // A multibyte string: [A] [B] [C] [katakana A] [D] []  
       // in Code Page 932. For this example to work correctly,  
       // the Japanese language support must be enabled by the  
       // operating system.  
       mbstr1 = "ABC" "x83x40" "D";  
      
       locale_string = setlocale(LC_CTYPE, "Japanese_Japan");  
      
       if (locale_string == NULL)  
       {  
          printf("Japanese locale not enabled. Exiting.
    ");  
          exit(1);  
       }  
       else  
       {  
          printf("Locale set to %s
    ", locale_string);  
       }  
      
       // _mbslen will recognize the Japanese multibyte character if the  
       // current locale used by the operating system is Japanese  
       printf("Length of '%s' : %d
    ", mbstr1, _mbslen(mbstr1) );  
      
       // _mbstrlen will recognize the Japanese multibyte character  
       // since the CRT locale is set to Japanese even if the OS locale  
       // isnot.   
       printf("Length of '%s' : %d
    ", mbstr1, _mbstrlen(mbstr1) );  
       printf("Bytes in '%s' : %d
    ", mbstr1, strlen(mbstr1) );     
      
    }  

    https://msdn.microsoft.com/en-us/library/78zh94ax.aspx

  • 相关阅读:
    屏幕适配的发展历史
    NSURLConnection / NSURLSession/ SDWebImage
    版本工具管理之----git
    Framework、Cocoa、Xcode
    UICollectionView-网格视图
    博客园每日一卦o(* ̄︶ ̄*)o
    平凡的程序猿
    如何使用java代码启动tomcat和打开浏览器
    web项目部署以及放到ROOT目录下
    java项目打包生成MD5文件
  • 原文地址:https://www.cnblogs.com/findumars/p/7296544.html
Copyright © 2011-2022 走看看