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

³B²zSTRING®É¹J¨ì§xÃø

³B²zSTRING®É¹J¨ì§xÃø

ªñ¤é¦b¼g¤@¨ÇFUNCTION¨Ó³B²z¤å¦r¡A¥i¬O¹J¨ì¤£¤Ö§xÃø¡A½Ð¦U¦ìÀ°¦£¤@¤U¡G

¥Ø¼Ð¡G¼g¤@­Ó¥sWORDªºFUNCTION¡A®ÄªG¬O­n§ä¥X¦r¦ê¤¤¥Ø¼Ð¦r²´¡AÃþ¦üINSTR¡A¦ý¤£¦P¡C¨Ò¦p¡G
STR = "Now is the time"
word(str, 1)= Now
word(str, 2)= is
  1. Sub Word()
  2. Dim str As String
  3. Dim str_out As String
  4. Dim i As Integer, j As Integer, c As Integer, a As Integer

  5. str = "Now is the time"
  6. str = Trim(str)
  7. str_out = ""
  8. a = 3
  9. c = 0


  10. For i = 1 To Len(str)

  11.     If c = a - 1 Then
  12.         For j = i To Len(str)
  13.             If Mid(str, j, 1) <> " " Then
  14.                 str_out = str_out & Mid(str, j, 1)
  15.                 Else
  16.                 Exit For
  17.             End If
  18.         Next j
  19.         i = j
  20.         If InStr(Mid(str, j), " ") <> 0 Then
  21.             i = j
  22.             c = c + 1
  23.         Else
  24.             i = j
  25.         End If
  26.     End If
  27.    
  28.    
  29.     If Mid(str, i, 1) <> " " Then
  30.         For j = i To Len(str)
  31.             If InStr(Mid(str, j), " ") = 0 Then
  32.             i = Len(str)
  33.             ElseIf Mid(str, j, 1) = " " Then
  34.                 i = j
  35.                 Exit For
  36.             End If
  37.         Next j
  38.     c = c + 1
  39.     End If

  40. Next i
  41. MsgBox str_out
½Æ»s¥N½X
³o¬qCODE¬O¥i¥H³B²z¤å¦r¤§¶¡¥u¦³¤@­ÓªÅ®æªº¦r¦ê¡A¦ý¦p¦ó¦r¦êÅܦ¨¡G"Now is    the time"
³o­Ó«K¤£¦æ¤F¡A¤£ª¾¹D¦U¦ì¦³¨S¦³¤èªk¸Ñ¨M¡HÁÂÁ¤j®a

¦^´_ 1# ¤p«L«È
  1. Function TRIM_Str(Mystr As String) As String
  2. Dim Ay()
  3. ar = Split(Mystr, " ")
  4. For Each a In ar
  5.   If a <> "" Then
  6.   ReDim Preserve Ay(s)
  7.   Ay(s) = a
  8.   s = s + 1
  9.   End If
  10. Next
  11. TRIM_Str = Join(Ay, " ")
  12. End Function


  13. Sub nn()
  14. MsgBox TRIM_Str("Now  is   the time")
  15. End Sub
½Æ»s¥N½X

TOP

ÁÂÁ¤j¤j¡AÁöµM§A¼gªº¥N½X¸ò§Úªº­ì·N¦³ÂI¤£¦P¡A¦]¬°§Úªº¥Øªº¬O©â¨ú¬Y¤@­Óµü¡A¨Ò¦p¡GWORD("§Ú ¬O  ¤@­Ó      ¨k   ¥Í", 3) = ¤@­Ó¡A¸òMID¦³ÂI¦ü¡A¦ý§Ú¬O¥Hµü²Õ¬°°ò¦¡C
§Ú§â§Aªº²z©À¥[¤J¡A¦¨¥\»s¦¨¤FWORD³o­ÓFUNCTION¤F¡C

§Ú¤§«e¤]¸Õ¹L¥Î"SPLIT"³o­Ó¥\¯à¡A¦ý§Ú¤@ª½¥H¬°SPLITªº¥Îªk¬O§â¦r¦ê©î¶}¡A¦A©ñ¤J¦C°}¤¤¡A¨Ò¦p¡GA()=SPLIT(STRING, " ")
§Ú§âSPLIT©ñ¦b¤W­±ªºCODE®É¡Aµo²{¤F¦³³¡¥÷ªº¦C°}¬OªÅªº¡A·Q¤£¨ì­ì¨Ó¥i¥H¥ÎREDIM PRESERVE§R¥h¡A¤Ó§Q®`¤F¡A¤S¦h¾Ç¤@­Ó¤èªk¡AÁÂÁ¡C

TOP

¦^´_ 3# ¤p«L«È
Sorry!!¨S¬Ý²M·¡§Aªº¥Î·N
  1. Function TheWord(Mystr As String, dot As String, i As Integer) As String
  2. Dim Ay()
  3. ar = Split(Mystr, dot)
  4. For Each a In ar
  5.   If a <> "" Then
  6.   ReDim Preserve Ay(s)
  7.   Ay(s) = a
  8.   s = s + 1
  9.   End If
  10. Next
  11. TheWord = Ay(i - 1)
  12. End Function


  13. Sub nn()
  14. Dim i As Integer
  15. For i = 1 To 4
  16.   MsgBox TheWord("Now  is   the time", " ", i)
  17. Next
  18. End Sub
½Æ»s¥N½X

TOP

¥»©«³Ì«á¥Ñ GBKEE ©ó 2012-8-24 12:07 ½s¿è

¦^´_ 3# ¤p«L«È
  1. Option Explicit
  2. Sub Ex()
  3.     Dim TheWord As String, xW As String, E
  4.     xW = "a"
  5.     TheWord = "§Úaaaaa¬Oaaaaa¤@­Óaaaaaaaaa¨k¥Í"
  6.     Do
  7.         TheWord = Replace(TheWord, String(2, xW), xW)
  8.     Loop While InStr(TheWord, String(2, xW))  '= True
  9.     For Each E In Split(TheWord, xW)
  10.         MsgBox E
  11.     Next
  12. End Sub
½Æ»s¥N½X

TOP

¦^´_ 4# white945


    ¤Q¤À·PÁ¡A³o¬O¥¿§Ú»Ý­nªº¥\¯à

TOP

¦^´_  ¤p«L«È
GBKEE µoªí©ó 2012-8-24 12:05

    §Ú¤]¥Î¹LREPLACE¡A¦ý·í³B²z¦h©ó¤@­ÓSPACE©Î¯S§O²Å¸¹®É´N·|¥X°ÝÃD¡A­ì¨Ó¥i¥H¥ÎSTRING + LOOPªº¤èªk
¨ü±Ð¤F¡C

¥t¥~¡A§Ú¥i¥H¦h°Ý¤@­Ó°ÝÃD¶Ü¡H¬OÃö©ó¤ÀªR¦r¦ê®É¦h±ø¥ó¿ï¾Üªº°ÝÃD
¨Ò¦p¡G§Ú­n¨ü³XªÌ¦^µª¥L¤l¤kªº¾Ç®Õ°Ï¤À©M¾Ç¾ú¡A¦pªG¨S¦³¤l¤k¡Aµª®×¯dªÅ¡AÂ൪¤U¤@ÃD
  1. If Ien(raw.Cells(i, 3)) > 0 Then
  2.     If InStr(raw.Cells(i, 3), "¤p¾Ç") + InStr(raw.Cells(i, 3), "ªì¤p") > 0 Then
  3.         type = "primary"
  4.         GoTo Define_unit
  5.     ElseIf InStr(raw.Cells(i, 3), "ªì¤¤") + InStr(raw.Cells(i, 3), "°ê¤¤")+ InStr(raw.Cells(i, 3), "°ª¤¤")  > 0 Then
  6.         type = "secondary"
  7.         GoTo Define_unit
  8.     ElseIf InStr(raw.Cells(i, 3), "¤j¾Ç") + InStr(raw.Cells(i, 3), "¤j±M")> 0 Then
  9.         type = "Uni"
  10.         GoTo Define_unit
  11.         
  12.     ElseIf InStr(raw.Cells(i, 3), "¬ã¨s©Ò") + InStr(raw.Cells(i, 3), "³Õ¤h") > 0 Then
  13.         type = "Master+"
  14.         GoTo Define_unit
  15.    
  16.     End If
  17.    
  18. Define_unit:
  19.         If InStr(raw.Cells(i, 3), "¥xÆW") > 0 Then unit = "TW"
  20.         If InStr(raw.Cells(i, 3), "­»´ä") > 0 Then unit = "HK"
  21.         If InStr(raw.Cells(i, 3), "¬ü°ê") > 0 Then unit = "US"
  22.     End If
½Æ»s¥N½X
¨Ò¦p¡Gµª®×¬O¡A§Ú¨à¤l¬O¦b¬ü°êŪ°ª¤¤
¨º»òunit = "US", TYPE=secondary

¦ý³o¸Ì¦³«Ü¦hIF THEN¡A¤S¤Óªø¡A¦³ÂI²V¶Ã¡C§Ú±N¤§§ï¥ÎGOTO¡A¤£¥Î­«½Æ¥X²{´X¦¸¬Û¦üªº¥y¤l¡C¦ý½Ð°Ý¥i¥H§ï¥Îselect case©Î¨ä¥L¤èªk²¤Æ¶Ü¡HÁÂÁÂ

TOP

¥»©«³Ì«á¥Ñ GBKEE ©ó 2012-8-28 09:15 ½s¿è

¦^´_ 7# ¤p«L«È
  1. If InStr(raw.Cells(i, 3), "¤p¾Ç") + InStr(raw.Cells(i, 3), "ªì¤p") > 0 Then  
  2.         '±ø¥ó : ¦p¤£¦¨¥ß, ·|§PÂ_¤U¤@­ÓElseIf±ø¥ó.¤@ª½¨ì¦³ElseIf±ø¥ó¦¨¥ß«á·|¤£¦A¥h§PÂ_¨ä¾lªº±ø¥ó,Â÷¶}¦¹ IF ....Then  ....Else  .....     End If
  3.         '¤£¥²   GoTo Define_unit
  4.         vbtype = "primary"                                                                                                            
  5.     ElseIf InStr(raw.Cells(i, 3), "ªì¤¤") + InStr(raw.Cells(i, 3), "°ê¤¤") + InStr(raw.Cells(i, 3), "°ª¤¤") > 0 Then
  6.         vbtype = "secondary"
  7.     ElseIf InStr(raw.Cells(i, 3), "¤j¾Ç") + InStr(raw.Cells(i, 3), "¤j±M") > 0 Then
  8.         vbtype = "Uni"
  9.     ElseIf InStr(raw.Cells(i, 3), "¬ã¨s©Ò") + InStr(raw.Cells(i, 3), "³Õ¤h") > 0 Then
  10.         vbtype = "Master+"
  11.     End If
  12.     If InStr((raw.Cells(i, 3), "¥xÆW") > 0 Then unit = "TW"
  13.     If InStr((raw.Cells(i, 3), "­»´ä") > 0 Then unit = "HK"
  14.     If InStr((raw.Cells(i, 3), "¬ü°ê") > 0 Then unit = "US"
½Æ»s¥N½X

TOP

¦^´_  ¤p«L«È
GBKEE µoªí©ó 2012-8-27 20:26



    ³o­ÓW¬O­n¥Î
set w = raw.cells(i,3)
¨Ó³]©w¶Ü¡H
­ì¨Ó¦p¦¹¡AÁÂÁª©¤j

³o»ò¡A¬O¤£¬Oselect case¥u¯à¥Î¤@­Ócondition?

TOP

¥»©«³Ì«á¥Ñ GBKEE ©ó 2012-8-28 09:48 ½s¿è

¦^´_ 9# ¤p«L«È
InStr(raw.Cells(i, 3), "¤p¾Ç")   ³o¥u·|¶Ç¦^¼Æ¦r
§A¦Û¦ê¤¤ ªì¤p, ¤p¾Ç,ªì¤¤, °ê¤¤.... ¨Ã¨S¦³©T©w¦b­þ­Ó¦ì¸m,¤£¾A¦X¥Î Select Case
  1. Select Case ÅܼƠ '
  2.       Case  ¼Æ¦r ©Î ¦r¦ê
  3. End Select
½Æ»s¥N½X

TOP

        ÀR«ä¦Û¦b : ¦Y­W¤F­W¡B­WºÉ¤Ü¨Ó¡A¨ÉºÖ¤FºÖ¡BºÖºÉ´d¨Ó¡C
ªð¦^¦Cªí ¤W¤@¥DÃD