计算机二级域乱码,09年计算机二级辅导:解决VC++程序国际化的类,解决乱码问题...

09年计算机二级辅导:解决VC++程序国际化的类,解决乱码问题

分类:计算机等级

|

更新时间:2016-07-07|

来源:中华网考试

#include "stdafx.h"

#include "global.hpp"

// Description: generate an error message

int Error(long err, char *fmt, ...)

{

static char buf[256];

static char buf2[256];

va_list args;

va_start(args, fmt);

vsprintf(buf, fmt, args);

sprintf(buf2, "Error: %s (HRESULT= 0x%x)", buf, err);

va_end(args);

AfxMessageBox(buf2);

TRACE2("Error: HRESULT: 0x%x, %s\n", err, buf);

return err;

}

// Description: returns the next complete word found starting at string

// index sIdx

int getWordFrom( CString &instr, int &sIdx, CString &word )

{

int len = instr.GetLength();

word = "";

if ( sIdx == len ) return FALSE;

for ( ; sIdx < len; sIdx++) { // find first nonspace

if (instr[sIdx] != ’ ’) break;

}

for (int e=sIdx; e < len; e++) { // find the first space

if (instr[e] == ’ ’) break;

}

if (sIdx == len) return FALSE;

word = instr.Mid(sIdx, esIdx);

sIdx = e;

return TRUE;

}

// Description: returns the nth word in instr. The word is returned in

// word.

int words( CString &instr )

{

int count = 0;

int idx = 0;

CString word("");

while (1) {

if ( ! getWordFrom( instr, idx, word ) ) break;

count++;

}

return count;

}

// Description: returns the nth word in instr. The word is returned in

// word.

int word( CString &instr, int n, CString &word )

{

int idx = 0;

word = "";

for (int i = 1; i <= n; i++) {

if ( ! getWordFrom( instr, idx, word ) ) break;

}

return (word != "");

}

// Description: returns a series of words in instr. The words are

// returned in word.

// Parameters: sn = starting word index (starts at 1)

// nw = # of words to retrieve (1 means remaining words)

int subword( CString &instr, int sn, int nw, CString &substr )

{

substr = "";

if (0 == nw) return TRUE; // OK, you asked for 0 words, you got 0 words

if (sn < 1) return FALSE; // bad parameter, word index starts at 1

int idx = 0;

CString word;

// first get to the first wanted word

for (int i = 1; i < sn; i++) {

if ( ! getWordFrom( instr, idx, word ) ) break;

}

// get all the words needed

i = 0;

while (1) {

if ( ! getWordFrom( instr, idx, word ) ) break;

if (i > 0) substr += " ";

substr += word;

if (++i == nw) break;

}

return (substr != "");

}

// Description: returns the index or the word that matches the character */

// position in the string */

int wordIdxFromCharIdx( CString &instr, int cIdx)

{

int idx = 0;

int wIdx = 0;

CString word;

while (1) {

if ( ! getWordFrom( instr, idx, word ) ) break;

wIdx++;

if ( cIdx < idx ) return wIdx;

}

return 0;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值