ab.com コミュニティ

ActiveBasicを通したコミュニケーション
現在時刻 - 2024年3月28日(木) 21:39

全ての表示時間は UTC+09:00 です




新しいトピックを投稿する  トピックへ返信する  [ 1 件の記事 ] 
作成者 メッセージ
投稿記事Posted: 2005年7月27日(水) 19:14 
オフライン

登録日時: 2005年5月31日(火) 17:59
記事: 899
お住まい: 東京都
URLエンコードをするURLEncode関数と、おまけでShift JISなどのMBCSからUTF8へ変換するToUTF8関数です。

さらにおまけで入力した文字列でGoogle検索をするプログラムを付属させています。
(こいつのためにToUTF8()を作ることになりました)
コード:
#console
TypeDef UINT = DWORD
TypeDef BOOL = Long
/*
Declare Function MultiByteToWideChar Lib "kernel32" (CodePage As UINT, dwFlags As DWORD, pMultiByteStr As BytePtr,
	cchMultiByte As Long, pWideCharStr As *WCHAR, cchWideChar As Long) As Long
*/
Declare Function WideCharToMultiByte Lib "kernel32" (CodePage As UINT, dwFlags As DWORD, pWideByteStr As *WCHAR,
	cchWideByte As Long, pMultiCharStr As BytePtr,cchMultiChar As Long, pDefaultChar As BytePtr, pUsedDefaultChar As *BOOL) As Long 

Function URLEncode(pFrom As BytePtr) As String
	Dim i = 0 As DWord
	While pFrom <> 0
		If IsCharAlphaNumeric(pFrom) Or InStr(1, "'.-*()_", Chr$(pFrom)) Then
			URLEncode = URLEncode + Chr$(pFrom)
		Else
			URLEncode = URLEncode + "%" + Hex$(pFrom)
		End If
		i = i + 1
	Wend
End Function

Function ToUTF8(pFrom As BytePtr) As String
	Dim Length As Long, BufSize As Long
	Length = lstrlen(pFrom)
	BufSize = (Length + 1) * SizeOf(WCHAR)
	Dim pWStr As *WCHAR
	pWStr = malloc(BufSize)
	Dim WStrLength As Long
	WStrLength = MultiByteToWideChar(CP_ACP, 0, pFrom, -1, pWStr, BufSize)
	Dim UTF8StrBufSize As Long
	UTF8StrBufSize = WideCharToMultiByte(CP_ACP, 0, pWStr, WStrLength, NULL, 0, NULL, NULL)
	ToUTF8 = ZeroString(UTF8StrBufSize - 1)
	WideCharToMultiByte(CP_ACP, 0, pWStr, WStrLength, ToUTF8, UTF8StrBufSize, NULL, NULL)
End Function

Dim str As String, strUTF8 As String, strEncoded As String, strURL As String
Input str
strUTF8 = ToUTF8(str)
strEncoded = URLEncode(StrPtr(strUTF8)) 
Print strEncoded
strURL = "http://www.google.co.jp/search?q=" + strEncoded
ShellExecute(0, NULL, StrPtr(strURL), NULL, NULL, SW_SHOW)


通報する
ページトップ
期間内表示:  ソート  
新しいトピックを投稿する  トピックへ返信する  [ 1 件の記事 ] 

全ての表示時間は UTC+09:00 です


オンラインデータ

このフォーラムを閲覧中のユーザー: なし & ゲスト[11人]


トピック投稿:  可
返信投稿:  可
記事編集: 不可
記事削除: 不可
ファイル添付: 不可

検索:
ページ移動:  
cron
Powered by phpBB® Forum Software © phpBB Limited
Japanese translation principally by ocean