strGBK

此博客展示了一段Java代码,定义了一个名为strGBK的类,其中包含一个isoTOgbk方法,用于将字符串从ISO - 8859 - 1编码转换为GBK编码,若输入为空则返回空字符串,同时处理了不支持编码的异常。

package zpxx;
import java.io.*;

public class strGBK
{
 public String isoTOgbk(String strMc)
 {
  if(strMc == null || strMc.length()==0)
  return "";
  try
  {
   strMc = new String(strMc.getBytes("ISO-8859-1"),"GBK");
  }
  catch(UnsupportedEncodingException usex)
  {
  }
  return strMc;
 }
}

#include "pch.h" #include "DbgLog.h" #include <ctime> #include "shlwapi.h" #pragma comment(lib, "shlwapi") //char DbgLog::LogPath[MAX_PATH] = "Printer_log.txt"; ofstream logfile; //streambuf *outstream; DbgLog::DbgLog(){} DbgLog::~DbgLog(){} void DbgLog::StartLog(TCHAR *LogName) { /* if(OFFONPRINTF) { TCHAR LogPath[MAX_PATH] = { 0 }; GetModuleFileName(NULL, LogPath, sizeof(LogPath)); PathRemoveFileSpec(LogPath); PathAppend(LogPath, LogName); logfile.open(LogPath, ios::app | ios::out); //outstream = std::cout.rdbuf(logfile.rdbuf()); time_t t = time(0); char tmp[64] = ""; tm newtime; localtime_s(&newtime, &t); strftime(tmp, sizeof(tmp), "%Y/%m/%d %H:%M:%S", &newtime); logfile << "-------------------------------------" << tmp << "-------------------------------------" << endl; } */ if(OFFONPRINTF) { TCHAR LogPath[MAX_PATH] = { 0 }; TCHAR LogFileName[MAX_PATH] = { 0 }; GetModuleFileName(NULL, LogPath, sizeof(LogPath)); PathRemoveFileSpec(LogPath); PathAppend(LogPath, L"project"); CreateDirectory(LogPath, NULL); PathAppend(LogPath, L"log"); CreateDirectory(LogPath, NULL); PathAppend(LogPath, LogName); CreateDirectory(LogPath, NULL); SYSTEMTIME sys; GetLocalTime(&sys); wsprintf(LogFileName, L"%04d%02d%02d%02d%02d.txt", sys.wYear, sys.wMonth, sys.wDay, sys.wHour, sys.wMinute); PathAppend(LogPath, LogFileName); logfile.open(LogPath, ios::app | ios::out); } } void DbgLog::EndLog() { if(OFFONPRINTF) { //std::cout.rdbuf(outstream); logfile.close(); } } void DbgLog::DbgPrint(CHAR* CppName, CHAR *FunName, INT CodeLine, CHAR* format, ...) { if(OFFONPRINTF) { char Buffer[1024] = {0}; va_list argp; va_start(argp, format); vsprintf_s(Buffer, format, argp); va_end(argp); logfile << TimeStrLog() << "[" << GetCurrentThreadId() << "][" << CppName << "][" << FunName << "][" << CodeLine << "] "; logfile << Buffer; logfile << flush; } } void DbgLog::DbgPrint(CHAR* CppName, CHAR *FunName, INT CodeLine, TCHAR* format, ...) { if (OFFONPRINTF) { TCHAR Buffer[1024] = { 0 }; CHAR cBuffer[2048] = { 0 }; va_list argp; va_start(argp, format); vswprintf_s(Buffer, format, argp); va_end(argp); wchar_to_char(cBuffer, Buffer, 2048); logfile << TimeStrLog() << "[" << GetCurrentThreadId() << "][" << CppName << "][" << FunName << "][" << CodeLine << "] "; logfile << cBuffer;// Buffer; logfile << flush; } } string DbgLog::TimeStrLog() { SYSTEMTIME sys; GetLocalTime(&sys); char TS[255] = ""; sprintf_s(TS, 255, "%04d-%02d-%02d %02d:%02d:%02d.%04d ", sys.wYear, sys.wMonth, sys.wDay, sys.wHour, sys.wMinute, sys.wSecond, sys.wMilliseconds); return &TS[0]; } int DbgLog::wchar_to_char(char *strGBK, LPCWSTR FileName, int strlen) { int len = WideCharToMultiByte(CP_ACP, 0, FileName, -1, NULL, 0, NULL, NULL); if(len > strlen){ return -1; } WideCharToMultiByte(CP_ACP, 0, FileName, -1, strGBK, len, NULL, NULL); return len; }cpp文件也要改吧
最新发布
12-20
/* * Copyright(C) 2016,Company 保留所有权利。( All rights reserved. ) * * 文件名称:DbgLog.h * 摘 要: * 当前版本:1.0 * 作 者: * 创建日期:2016年7月19 */ #ifndef _DBGPRINTF_H_ #define _DBGPRINTF_H_ #include <iostream> #include <fstream> #include <tchar.h> #include <string> #include <windows.h> using namespace std; #ifdef _DEBUG #define OFFONPRINTF 1 #else #define OFFONPRINTF 0 #endif #if OFFONPRINTF #define DBG_GET_FILE() __FILE__ #define DBG_GET_FUNCTION() __FUNCTION__ #define DGB_GET_LINE() __LINE__ #else #define DBG_GET_FILE() "" #define DBG_GET_FUNCTION() "" #define DGB_GET_LINE() 0 #endif #define GETFILENAME(x) ((strrchr(x, '\\' )) ? (strrchr(x, '\\') + 1) : (x)) #if OFFONPRINTF #define LOGPRINT(str, ...) \ DbgLog::DbgPrint( \ (char*)GETFILENAME(DBG_GET_FILE()), \ (char*)DBG_GET_FUNCTION(), \ DGB_GET_LINE(), \ (str), ##__VA_ARGS__) #else #define LOGPRINT(str, ...) #endif class DbgLog { public: DbgLog(); ~DbgLog(); /************************************************************************ * 函数名:StartLog * 功 能:开始打印 * 参 数:无 * 返回值:无 ************************************************************************/ static void StartLog(TCHAR *LogName); /************************************************************************ * 函数名:EndLog * 功 能:结束打印 * 参 数:无 * 返回值:无 ************************************************************************/ static void EndLog(); /************************************************************************ * 函数名:DbgPrint * 功 能:输出日志 * 参 数: * @format: * 返回值:无 ************************************************************************/ static void DbgPrint(CHAR* CppName, CHAR *FunName, INT CodeLine, CHAR* format, ...); static void DbgPrint(CHAR* CppName, CHAR *FunName, INT CodeLine, TCHAR* format, ...); protected: private: /************************************************************************ * 函数名:TimeStrLog * 功 能:获取日期 * 参 数: * 返回值:以字符串返回日期格式 ************************************************************************/ static string TimeStrLog(); /************************************************************************ * 函数名:wchar_to_char * 功 能: * 参 数: * 返回值: ************************************************************************/ static int wchar_to_char(char *strGBK, LPCWSTR FileName, int strlen); //ofstream logfile; //wofstream logfileW; //streambuf *outstream; //wstreambuf *outstreamW; static char LogPath[MAX_PATH]; }; #endif 给我增加一个LOGINFO想LOGPRINT一样,但是不一样的是LOGINFO可以release模式输出
12-20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值