ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

½Ð±Ðmid¡Bmidb¡Blen¡Blenb°ÝÃD

½Ð±Ðmid¡Bmidb¡Blen¡Blenb°ÝÃD

¤j®a¦n¡G
·Q½Ð±Ð len()·fmid()­^¼Æ¦r­û»P¤¤¤å¦r¤¸¡Alenb()·fmidb()­^¼Æ¤¤¤å¦r¤¸ºâªk

§Ú¦³»s§@¤@­Ó½d¨Ò°ÝÃD ¬¡­¶Ã¯1.rar (12.48 KB)

§ÚªººÃ°Ý¬Omidb¡Blenb¹ï­^¼Æ¬°¦ó¤]¬OÂù¦r¤¸
¦³¿ìªkÅý­^¼Æºâ³æ¦r¤¸¡A¤¤¤åºâÂù¦r¤¸ªº¤èªk¶Ü?
lionliu

¦^´_ 1# lionliu

§Aªº½d¨Ò¤¤ A1 = "abc123, abc 123 abc123§Ú·d¤£©w MID( ),MIDB( )¡ALEN( ) LENB( ) stuwxyz"

LEN(A1) = 64
LENB(A1) = 69
ªí¥Ü 69-64=5 ¦³5­ÓÂù¦r¤¸

¤£¤F¸Ñ§A­n¨D¬Æ»ò?
{...} ªí¥Ü»Ý­n¥Î CTRL+SHIFT+ENTER ¤TÁä¿é¤J¤½¦¡

TOP

¦^´_ 2# ML089
ÁÂÁª©¤j¦^ÂÐ
§Úªº°ÝÃD¬Omidb(range,1,20)¬°¤°»ò­^¼Æ³£ºâÂù¦r¤¸¡C
§Úªº»Ý¨D¬O20¦r¤¸¡A­^¼Æ¤¤¤å²V¦X¡C
lionliu

TOP

¦^´_ 3# lionliu

½Ð¬Ý³o½g»¡©ú
    http://forum.twbts.com/thread-31-1-1.html



Len ¨ç¼Æ½d¨Ò
²Ä¤@­Ó½d¨Ò¨Ï¥Î Len ¶Ç¦^¬Y¦r¦êªºªø«×(¦r¤¸¼Æ)©Î¬YÅܼƪº¤j¤p(¦ì¤¸¼Æ)¡CType...End Type µ{¦¡°Ï¶ô©w¸q¤@­Ó¦Û­q¸ê®Æ«¬ºA CustomerRecord¡C¦pªG¸Ó¸ê®Æ«¬ºA©w¸q¦bª«¥óÃþ§O¼Ò²Õ¤¤¡A«h¥²»Ý¥HÃöÁä¦r Private ¶}ÀY(ªí¥Ü¬°¨p¦³)¡C­Y©w¸q¦b¤@¯ë¼Ò²Õ¤¤¡AType ©w¸q´N¥i¥H¬° Public¡C

Type CustomerRecord    ' ©w¸q¨Ï¥ÎªÌ¦Û­qªº¸ê®Æ«¬ºA¡C
    ID As Integer    ' ±N¦¹©w¸q©ñ¦b¤@¯ë¼Ò²Õ¤¤¡C
    Name As String * 10
    Address As String * 30
End Type

Dim Customer As CustomerRecord    ' «Å§iÅܼơC
Dim MyInt As Integer, MyCur As Currency
Dim MyString, MyLen
MyString = "Hello World"    ' ³]©wÅܼƪì­È¡C
MyLen = Len(MyInt)    ' ¶Ç¦^ 2¡C
MyLen = Len(Customer)    ' ¶Ç¦^ 42¡C
MyLen = Len(MyString)    ' ¶Ç¦^ 11¡C
MyLen = Len(MyCur)    ' ¶Ç¦^ 8¡C

¦pªG¥ÎANSIªí¥Ü¦r¦êªº¸Ü¡A²Ä¤G­Ó½d¨Ò¨Ï¥Î LenB©M¨Ï¥ÎªÌ©w¸qªº¨ç¼Æ (LenMbcs) ¶Ç¦^¬Y¦r¦êªºªø«×(¦r¤¸¼Æ)¡C

Function LenMbcs (ByVal str as String)
    LenMbcs = LenB(StrConv(str, vbFromUnicode))
End Function

Dim MyString, MyLen
MyString = "ABc"
' "A" ©M "B" ¬O DBCS¥B "c" ¬OSBCS¡C
MyLen = Len(MyString)
' ¶Ç¦^¦r¦ê¤¤¦³3 ¡V3 ­Ó¦r¤¸¡C
MyLen = LenB(MyString)
' ¶Ç¦^ 6 ¡V 6 ¦ì¤¸¥Î©óUnicode¡C
MyLen = LenMbcs(MyString)
' ¶Ç¦^ 5 - 5­Ó¦ì¤¸¥Î©óANSI¡C
{...} ªí¥Ü»Ý­n¥Î CTRL+SHIFT+ENTER ¤TÁä¿é¤J¤½¦¡

TOP

¥»©«³Ì«á¥Ñ lionliu ©ó 2016-1-18 09:42 ½s¿è

¦^´_ 3# lionliu

ÁÂÁÂml¤j­ô¡A§Ú¦b´ú¸Õ¤@¤U¡C
lionliu

TOP

¥[¤J
Function xMidB(ByVal str As String, start, length)
    xMidB = StrConv(MidB(StrConv(str, vbFromUnicode), start, length), vbUnicode)
End Function

Function xLenB(ByVal str As String)
    xLenB = LenB(StrConv(str, vbFromUnicode))
End Function

±N­ìµ{¦¡¤¤ªº LenB §ï¬° xLenB
±N­ìµ{¦¡¤¤ªº MidB §ï¬° xMidB
{...} ªí¥Ü»Ý­n¥Î CTRL+SHIFT+ENTER ¤TÁä¿é¤J¤½¦¡

TOP

¥»©«³Ì«á¥Ñ ­ã´£³¡ªL ©ó 2016-1-18 15:45 ½s¿è

¸û²³æªº¤èªk¡G
xLenB = Evaluate("LenB(""" & Range("A1") & """)")
MsgBox xLenB

­Y¤¤¤å§t¦³¡e²Åé¦r¡f©Î¨ä¥¦¥~¦r½X¥þ«¬¦r¡AxLenB ·|¶Ç¦^¢°¡A©Ò¥HÁÙ¬O¤£¥i¾a¡A
¨Ò¦p¡G堃¡D々¡D国¡D龥....µ¥µ¥

¥i¦Ò¼{¡e¥¿«h¡f¤èªk¡A¦ý§Ú¤£¼ô¥Î¡A½Ð¤Wºô§ä²{¦¨¬Ý¬Ý¡ã¡ã

TOP

¦^´_ 7# ­ã´£³¡ªL
ÁÂÁ Mj»P­ã¤j2¦ì¤j­ôªº¦^ÂСA­ì¨ÓmedbÁÙ­n³o¼Ë§ï¡A§Ú·Q»¡¤@ª½¥X²{¶Ã½X¤£ª¾­þ¨½¥X¿ù¥¿·Q¦A½Ð±Ð¡C§Ú¦A¸Õ¬Ý¬Ý¡C
lionliu

TOP

¦^´_ 6# ML089
ÁÂÁÂMJ¤j¤j¡G
§Ú´ú¸Õ«á³£¥¿±`¤F¡C
lionliu

TOP

¥»©«³Ì«á¥Ñ lionliu ©ó 2016-1-19 15:30 ½s¿è

¦^´_ 6# ML089
¦^´_ 8# ­ã´£³¡ªL
2¦ì¤j­ô¦n¡G
¸g¹L´ú¸Õ«áµo²{2­Ó°ÝÃD¡Amj¤j¤jªº¤èªk­Y¤¤¤å¦r¦ê­è¦n¦b¤Á³ÎÂI·|Åܦ¨?¡A¤U¤@¦æ²Ä¤@®æ¦r¤]¬O?¡A¤¤¤å¦r­å¥b¡C

­ã¤jªº¤èªk§Ú²Ä¤@¦¸¥Îmidb¤£·|§ï¡A§Ú¹L§Ú¥Î¤FÃþ¦¡ªº²Â¤èªk¡A"=midb(a1,1,20)"¥´¤½¦¡ªº¤è¦¡¡Aµ²ªG·|¦n¤@ÂI¡A¦ý¬Oµo²{·|±¼¦r(¤¤¤å¦r­è¦n¦b¤À³ÎÂI®É)¡A¥Ø«e©|¦b¬ã¨s´ú¸Õ¤¤¡C
lionliu

TOP

        ÀR«ä¦Û¦b : ºw¤ô¦¨ªe¡C²É¦Ì¦¨ÅÚ¡A¤Å»´¤vÆF¡A¤Å¥Hµ½¤p¦Ó¤£¬°¡C
ªð¦^¦Cªí ¤W¤@¥DÃD