【已解决】如何在 ahk unicode 中获取真实的字节长度?

Post a reply


In an effort to prevent automatic submissions, we require that you complete the following challenge.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :| :mrgreen: :geek: :ugeek: :arrow: :angel: :clap: :crazy: :eh: :lolno: :problem: :shh: :shifty: :sick: :silent: :think: :thumbup: :thumbdown: :salute: :wave: :wtf: :yawn: :facepalm: :bravo: :dance: :beard: :morebeard: :xmas: :HeHe: :trollface: :cookie: :rainbow: :monkeysee: :monkeysay: :happybday: :headwall: :offtopic: :superhappy: :terms: :beer:
View more smilies

BBCode is ON
[img] is OFF
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: 【已解决】如何在 ahk unicode 中获取真实的字节长度?

Re: 【已解决】如何在 ahk unicode 中获取真实的字节长度?

Post by aamii » 18 Sep 2014, 23:46

好方法,学到。
strput那个确快很多

Re: 【已解决】如何在 ahk unicode 中获取真实的字节长度?

Post by tmplinshi » 18 Sep 2014, 23:08

lexikos 提供了这个方法,又比上面更快! :mrgreen:

Code: Select all

StrLenA(str) {
	Return StrPut(str, "cp0") - 1
}

Re: 【已解决】如何在 ahk unicode 中获取真实的字节长度?

Post by tmplinshi » 18 Sep 2014, 21:40

Code: Select all

StrLenA(str) {
	Return DllCall("MSVCRT.DLL\strlen", "AStr", str)
}
经测试,这样更快。

Re: 【已解决】如何在 ahk unicode 中获取真实的字节长度?

Post by tmplinshi » 18 Sep 2014, 20:34

谢谢,速度快多了!

Re: 如何在 ahk unicode 中获取真实的字节长度?

Post by aamii » 18 Sep 2014, 19:29

试试

Code: Select all

 MsgBox, % StrLen(regexreplace("1全角","[^\x00-\xff]","11"))

【已解决】如何在 ahk unicode 中获取真实的字节长度?

Post by tmplinshi » 18 Sep 2014, 12:41

比如 StrLen("1全角") 在 ANSI 中的结果是 5,而 Unicode 中的结果是 3。

我的问题是,如何能在 Unicode 中也获得结果 5?

更新: 找到了一个方法

Code: Select all

MsgBox, % StrLenA("1全角")

StrLenA(string) { ; 注: 不太正确,全角符号不能计算为2
	Loop, Parse, string
		len += ( Asc(A_LoopField) < 0x2E80 or Asc(A_LoopField) > 0x9FFF ) ? 1 : 2
	Return len
}
有更好的方法吗?

Top