亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

C.串() 僅返回第一個字符

C.串() 僅返回第一個字符

Go
滄海一幻覺 2022-10-04 18:52:04
我正在嘗試使用c共享(.so)文件從Python調用Go函數。在我的python代碼中,我調用的函數如下所示:website = "https://draftss.com"domain = "draftss.com"website_ip = "23.xxx.xxx.xxx"website_tech_finder_lib = cdll.LoadLibrary("website_tech_finder/builds/websiteTechFinder.so")result_json_string: str = website_tech_finder_lib.FetchAllData(website, domain, website_ip)在Go端,我正在根據這篇SO帖子將字符串轉換為Go字符串(從共享庫訪問函數時內存不足):func FetchAllData(w *C.char, d *C.char, dIP *C.char) *C.char {    var website string = C.GoString(w)    var domain string = C.GoString(d)    var domainIP string = C.GoString(dIP)    fmt.Println(website)    fmt.Println(domain)    fmt.Println(domainIP)        .... // Rest of the code}網站域和 domainIP 只有我傳遞的字符串的第一個字符:fmt.Println(website)  // -> hfmt.Println(domain)   // -> dfmt.Println(domainIP) // -> 2我對Go有點陌生,所以我不確定我是否在這里做了一些愚蠢的事情。如何獲取我傳遞的完整字符串?
查看完整描述

1 回答

?
元芳怎么了

TA貢獻1798條經驗 獲得超7個贊

您需要將參數轉換為 UTF8 字節。


website = "https://draftss.com".encode('utf-8')

domain = "draftss.com".encode('utf-8')

website_ip = "23.xxx.xxx.xxx".encode('utf-8')


lib = cdll.LoadLibrary("website_tech_finder/builds/websiteTechFinder.so")

result_json_string: str = website_tech_finder_lib.FetchAllData(website, domain, website_ip)


查看完整回答
反對 回復 2022-10-04
  • 1 回答
  • 0 關注
  • 116 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號