如何用EXCEL VBA將漢字轉成GB2312的URL編碼,如輸入 中國 ,生成 D6 D0 B9 FA ,用於網路查詢

2022-04-06 14:35:49 字數 2064 閱讀 5172

1樓:巴哥泡泡

據說有 multibytetowidechar 和 widechartomultibyte 這兩個函式可以使用,但是我沒用過!

寫了2個函式,自己改吧!

public function uncode(x as range) as string

on error resume next

msgbox asc(mid(x, 1, 1)) + 65536

if x.columns.count <> 1 then

uncode = "error"

exit function

end if

if len(x) = 0 then exit function

dim a, b, c, i

b = ""

for i = 1 to len(x)

a = mid(x, i, 1)

if asc(a) < 0 then

uncode = uncode & sixteen(asc(a) + 65536)

else

uncode = uncode & a

end if

next

end function

public function sixteen(m as long) as string

n = m

x = "": y = ""

do while n <> 0

a = n mod 2

n = n \ 2

x = a & x

loop

do while len(x) mod 4 <> 0

x = "0" + x

loop

do while len(x) > 0

select case right(x, 4)

case "0000"

y = "0" + y

case "0001"

y = "1" + y

case "0010"

y = "2" + y

case "0011"

y = "3" + y

case "0100"

y = "4" + y

case "0101"

y = "5" + y

case "0110"

y = "6" + y

case "0111"

y = "7" + y

case "1000"

y = "8" + y

case "1001"

y = "9" + y

case "1010"

y = "a" + y

case "1011"

y = "b" + y

case "1100"

y = "c" + y

case "1101"

y = "d" + y

case "1110"

y = "e" + y

case "1111"

y = "f" + y

end select

x = left(x, len(x) - 4)

loop

sixteen = y

end function

如何用excel 的vba實現數字漢字拆分?

2樓:汲芮歡

具體方法是:

sub z()

dim s as string, i as longs = "aa往ddd往aa"

i = 1

do while i < len(s) - 1if (asc(mid(s, i, 1)) and 128) <> (asc(mid(s, i + 1, 1)) and 128) then

s = left(s, i) & "^" & right(s, len(s) - i)

i = i + 1 '1為插入字元"^"的長度,注意要一致,否則進入死迴圈

end if

i = i + 1

loop

msgbox s

end sub

如何用EXCEL VBA讀入固定格式的

參考下 sub readfile dim ddate as date dim scustomer as string dim sproduct as string dim dprice as double dim sfname as string dim ifnumber as integer fi...

如何用C將數字1轉換成字元

include int main 上面迴圈結束後,str得到的是 54321 的倒序 所以迴圈處理將12345放入另外一個陣列for i 0,c c 1 c 0 i c printf s n str1 return 0 在中的函式是itoa。功能 把一整數轉換為字串。char itoa int va...

如何用ecel將多個數仍數,如何用excel將多個數取對數

假設原資料在a列,需要在b對應a的數值,求出自然對數1 在b2 輸入公式 ln a1 回車見圖一2 選中b2,下拉填充至b列 下面,效果見圖二 你可以先取一個數的對數,然後下拉,就可以了 對多個數分別取對數嗎?log a1 下拉 先取一個的對數。然後填充就可以了。如何用excel2013把一列資料取...