C 文字列操作 新しいページはコチラ
提供: yonewiki
(→文字列長取得) |
|||
83行: | 83行: | ||
_tsetlocale(LC_ALL, _T("Japanese")); | _tsetlocale(LC_ALL, _T("Japanese")); | ||
const char *cStr1[]={"", "表示:よねウィキの機能<yonewiki>", "表示:よねウィキの機能1<yonewiki>", "表示:よねウィキの機能2<yonewiki>"}; | const char *cStr1[]={"", "表示:よねウィキの機能<yonewiki>", "表示:よねウィキの機能1<yonewiki>", "表示:よねウィキの機能2<yonewiki>"}; | ||
− | char **ppcStr1 = new char* [sizeof( | + | char **ppcStr1 = new char* [sizeof(cStr1)/sizeof(*cStr1)]; |
_tprintf(_T("const マルチバイト文字→マルチバイト文字コピー→_mbslen関数2バイト文字認識文字列長探索\n")); | _tprintf(_T("const マルチバイト文字→マルチバイト文字コピー→_mbslen関数2バイト文字認識文字列長探索\n")); | ||
− | for(int i = 0; i < (sizeof( | + | for(int i = 0; i < (sizeof(cStr1)/sizeof(*cStr1)); i++){ |
ppcStr1[i] = new char[strlen(cStr0[i]) + 1];//まずは単純に文字列をコピーするための領域を確保。 | ppcStr1[i] = new char[strlen(cStr0[i]) + 1];//まずは単純に文字列をコピーするための領域を確保。 | ||
91行: | 91行: | ||
} | } | ||
− | for(int i = 0; i < (sizeof( | + | for(int i = 0; i < (sizeof(cStr1)/sizeof(*cStr1)); i++){ |
− | printf("%2d/%2d: | + | printf("%2d/%2d:cStr1[%2d]=%s\nStrCount=%d\n\n",i, sizeof(cStr1)/sizeof(*cStr1),i, ppcStr1[i],_mbslen(reinterpret_cast<unsigned char*>(ppcStr1[i]))); |
} | } | ||
} | } | ||
100行: | 100行: | ||
<syntaxhighlight lang="cpp"> | <syntaxhighlight lang="cpp"> | ||
const マルチバイト文字→マルチバイト文字コピー→_mbslen関数2バイト文字認識文字列長探索 | const マルチバイト文字→マルチバイト文字コピー→_mbslen関数2バイト文字認識文字列長探索 | ||
− | 0/ 4: | + | 0/ 4:cStr1[ 0]= |
StrCount=0 | StrCount=0 | ||
− | 1/ 4: | + | 1/ 4:cStr1[ 1]=表示:よねウィキの機能<yonewiki> |
StrCount=21 | StrCount=21 | ||
− | 2/ 4: | + | 2/ 4:cStr1[ 2]=表示:よねウィキの機能1<yonewiki> |
StrCount=22 | StrCount=22 | ||
− | 3/ 4: | + | 3/ 4:cStr1[ 3]=表示:よねウィキの機能2<yonewiki> |
StrCount=22 | StrCount=22 | ||
119行: | 119行: | ||
_tsetlocale(LC_ALL, _T("Japanese")); | _tsetlocale(LC_ALL, _T("Japanese")); | ||
const char *cStr1[]={"", "表示:よねウィキの機能<yonewiki>", "表示:よねウィキの機能1<yonewiki>", "表示:よねウィキの機能2<yonewiki>"}; | const char *cStr1[]={"", "表示:よねウィキの機能<yonewiki>", "表示:よねウィキの機能1<yonewiki>", "表示:よねウィキの機能2<yonewiki>"}; | ||
− | char **ppcStr1 = new char* [sizeof( | + | char **ppcStr1 = new char* [sizeof(cStr1)/sizeof(*cStr1)]; |
_tprintf(_T("const マルチバイト文字→_mbstrlen関数2バイト文字認識文字列長探索\n")); | _tprintf(_T("const マルチバイト文字→_mbstrlen関数2バイト文字認識文字列長探索\n")); | ||
− | for(int i = 0; i < (sizeof( | + | for(int i = 0; i < (sizeof(cStr1)/sizeof(*cStr1)); i++){ |
− | printf("%2d/%2d: | + | printf("%2d/%2d:cStr1[%2d]=%s\nStrCount=%d\n\n",i, sizeof(cStr1)/sizeof(*cStr1),i, cStr1[i],_mbstrlen(cStr1[i])); |
} | } | ||
} | } |