使用Delphi6以上版本有AnsiToUTF8可用
Delphi5以下可使用
http://blog.teatime.com.tw/1/post/419
提供的方案轉編碼
unit util_utf8;
interface
uses Windows;
type
UTF8String = AnsiString;
function AnsiToWide(const S: AnsiString): WideString;
function WideToUTF8(const WS: WideString): UTF8String;
function AnsiToUTF8(const S: AnsiString): UTF8String;
function UTF8ToWide(const US: UTF8String): WideString;
function WideToAnsi(const WS: WideString): AnsiString;
function UTF8ToAnsi(const S: UTF8String): AnsiString;
implementation
function AnsiToWide(const S: AnsiString): WideString;
var len: integer;
ws: WideString;
begin
Result:='';
if (Length(S) = 0) then
exit;
len:=MultiByteToWideChar(CP_ACP, 0, PChar(s), -1, nil, 0);
SetLength(ws, len);
MultiByteToWideChar(CP_ACP, 0, PChar(s), -1, PWideChar(ws), len);
Result:=ws;
end;
function WideToUTF8(const WS: WideString): UTF8String;
var len: integer;
us: UTF8String;
begin
Result:='';
if (Length(WS) = 0) then
exit;
len:=WideCharToMultiByte(CP_UTF8, 0, PWideChar(WS), -1, nil, 0, nil, nil);
SetLength(us, len);
WideCharToMultiByte(CP_UTF8, 0, PWideChar(WS), -1, PChar(us), len, nil, nil);
Result:=us;
end;
function AnsiToUTF8(const S: AnsiString): UTF8String;
begin
Result:=WideToUTF8(AnsiToWide(S));
end;
function UTF8ToWide(const US: UTF8String): WideString;
var len: integer;
ws: WideString;
begin
Result:='';
if (Length(US) = 0) then
exit;
len:=MultiByteToWideChar(CP_UTF8, 0, PChar(US), -1, nil, 0);
SetLength(ws, len);
MultiByteToWideChar(CP_UTF8, 0, PChar(US), -1, PWideChar(ws), len);
Result:=ws;
end;
function WideToAnsi(const WS: WideString): AnsiString;
var len: integer;
s: AnsiString;
begin
Result:='';
if (Length(WS) = 0) then
exit;
len:=WideCharToMultiByte(CP_ACP, 0, PWideChar(WS), -1, nil, 0, nil, nil);
SetLength(s, len);
WideCharToMultiByte(CP_ACP, 0, PWideChar(WS), -1, PChar(s), len, nil, nil);
Result:=s;
end;
function UTF8ToAnsi(const S: UTF8String): AnsiString;
begin
Result:=WideToAnsi(UTF8ToWide(S));
end;
end.
該方案有一個小小的bug
就是WideToUTF8 回傳的結果最後會加上一個換行符號
造成轉碼後的結果可能會跟預期不一樣。
最後可使用 S:= copy(S,0,Length(S)-1);
以修正預期產出之結果。
2013年8月16日 星期五
2012年11月15日 星期四
如何才能在收hotmail時不要自動登入Messenger
自從在hotmail改版之後,
每次在打開hotmail時,
都會自動"幫"我登入Messenger
感覺很無言…
難到只想單純使用hotmail也是種錯?
在改版之前,
只需要使用「快速檢視」下端的Messenger 點選登出之後。
就不會再自動登入Messenger了。
----------經過Google之後終於找到正解了。----------
將滑鼠移到 Hotmail 視窗右上角使用者帳號名稱處約 2~3 秒,
系統會跳出一個功能表,選擇「登出 Messenger」後。
終於可以離開每次在打開hotmail時,
都會自動"幫"我登入Messenger的生活了唷…
偉大的資料來源: http://www.james-only.com/2010/08/03/623/
每次在打開hotmail時,
都會自動"幫"我登入Messenger
感覺很無言…
難到只想單純使用hotmail也是種錯?
在改版之前,
只需要使用「快速檢視」下端的Messenger 點選登出之後。
就不會再自動登入Messenger了。
----------經過Google之後終於找到正解了。----------
將滑鼠移到 Hotmail 視窗右上角使用者帳號名稱處約 2~3 秒,
系統會跳出一個功能表,選擇「登出 Messenger」後。
終於可以離開每次在打開hotmail時,
都會自動"幫"我登入Messenger的生活了唷…
偉大的資料來源: http://www.james-only.com/2010/08/03/623/
2012年11月12日 星期一
com.jacob.com.ComFailException: VariantChangeType failed
使用JACOB操作WORD時出現錯誤。
錯誤訊息是 com.jacob.com.ComFailException: VariantChangeType failed
原本程式都可以正常運作,移機之後出現的怪問題啊!!
新增二個資料夾就解決了= =||||
C:\Windows\SysWOW64\config\systemprofile\Desktop
C:\Windows\System32\config\systemprofile\Desktop
終於看見WORD正常的運作了
資料來源:
http://blog.csdn.net/zcmssd/article/details/7443502
http://bytes.com/topic/c-sharp/answers/819740-c-service-excel-application-workbooks-open-fails-when-called-service#post3514712
2012年11月8日 星期四
7-zip 9.20版怪事
近日將遠瑞win2003 server 之ghost檔備份回公司電腦。
因為檔案過大,
所以使用 7-zip 32bit 9.20版 進行壓縮檔設定成分割壓縮,
每個分割檔設定1mb(因為網路很容斷線),
一共壓了6千多個檔案。
經過網路 努力下載之後.....
經過網路 努力下載之後.....
經過網路 努力下載之後.....
在本機端 為win 7 64bit
當然是安裝 7-zip 64bit 9.20版 的安裝檔
解壓縮居然會出錯!!! =___=
打開壓縮檔時,出現不明的錯誤。
看著巨大的6千多個分割檔,
可不想重新下載。
後來試了移除7-zip 64bit 9.20版
再win7上安裝 7-zip 32bit 9.20版 解壓就成功了。
這…是…什…麼…道…理。
特以此文記錄。
因為檔案過大,
所以使用 7-zip 32bit 9.20版 進行壓縮檔設定成分割壓縮,
每個分割檔設定1mb(因為網路很容斷線),
一共壓了6千多個檔案。
經過網路 努力下載之後.....
經過網路 努力下載之後.....
經過網路 努力下載之後.....
在本機端 為win 7 64bit
當然是安裝 7-zip 64bit 9.20版 的安裝檔
解壓縮居然會出錯!!! =___=
打開壓縮檔時,出現不明的錯誤。
看著巨大的6千多個分割檔,
可不想重新下載。
後來試了移除7-zip 64bit 9.20版
再win7上安裝 7-zip 32bit 9.20版 解壓就成功了。
這…是…什…麼…道…理。
特以此文記錄。
2012年9月11日 星期二
The constructor BASE64Encoder() is not accessible due to restriction on required library
修改之前早已經部屬到客戶端的程式,還沒修改前就居然出錯。
出現訊息為
Access restriction: The constructor BASE64Encoder() is not accessible due to restriction on required library
GOOGLE一下之後發現
在project build path中先移除JRE System Library,再加回JRE System Library,重新組譯後就一切正常了。
=___=
資料來源
http://www.rouselife.com/aspx/Detail.aspx?id=4097
2012年6月3日 星期日
VS2010 Crystal Report SubReport 遺漏參數值
VS2010 Crystal Report SubReport 遺漏參數值(missing parameter values )
應該是個BUG !?
變更子報表連結 > 勾選(check) 根據欄位選取子報表中的資料(Select data in subreport based on field) > 確定
列印報表。此時會出現錯誤。
錯誤為:遺漏參數值
在這個點卡了半天,參數明明有設定。
解決方法… 再回到 變更子報表連結 > 不勾選(uncheck) 根據欄位選取子報表中的資料(Select data in subreport based on field) > 確定
列印報表。成功。
自行新增需要連結至子報表之參數值即可。
資料來源
http://itgroup.blueshop.com.tw/Gpx1981/gpx1981?n=convew&i=8934
應該是個BUG !?
變更子報表連結 > 勾選(check) 根據欄位選取子報表中的資料(Select data in subreport based on field) > 確定
列印報表。此時會出現錯誤。
錯誤為:遺漏參數值
在這個點卡了半天,參數明明有設定。
解決方法… 再回到 變更子報表連結 > 不勾選(uncheck) 根據欄位選取子報表中的資料(Select data in subreport based on field) > 確定
列印報表。成功。
自行新增需要連結至子報表之參數值即可。
資料來源
http://itgroup.blueshop.com.tw/Gpx1981/gpx1981?n=convew&i=8934
2011年12月21日 星期三
session cookie without secure flag set
Cookie Secure Flag 設定:
● PHP
setcookie ("TestCookie", "", time() - 3600, “/", ".example.com", 1);
● JSP
cookie.setSecure(true);
● ASP.NET
cookie.Secure = True;
資料來源
http://www.openfoundry.org/index.php?option=com_content&task=view&id=2354&Itemid=56;isletter=1
● PHP
setcookie ("TestCookie", "", time() - 3600, “/", ".example.com", 1);
● JSP
cookie.setSecure(true);
● ASP.NET
cookie.Secure = True;
資料來源
http://www.openfoundry.org/index.php?option=com_content&task=view&id=2354&Itemid=56;isletter=1
訂閱:
文章 (Atom)