SUB QueryStringParser(strStr, arrName(), arrValue())
 
 DIM nNextStartPoint, sItem, nValuePoint, nCount, sValue
 nNextStartPoint = 0 : nCount = 0
 
 DO UNTIL Instr(strStr, "&") = 0
   nNextStartPoint = instr(strStr, "&")
  sItem =  LEFT(strStr, nNextStartPoint )
  nValuePoint = instr(sItem, "=")
  arrName(nCount) = LEFT(sItem, nValuePoint - 1)
  arrValue(nCount) = MID(sItem, nValuePoint+1, len(sItem) - (nValuePoint+1))
  strStr = MID(strStr, nNextStartPoint+1)
 
  nCount = nCount + 1
 LOOP
 
 sItem = strStr
 nValuePoint = instr(sItem, "=")
 arrName(nCount) = LEFT(sItem, nValuePoint - 1)
 arrValue(nCount) = MID(sItem, nValuePoint+1)
 
END SUB


예 >
DIM arrName(10), arrValue(10), nCount, strQueryString

strQueryString = "1=a&2=b&3=c"
CALL  QueryStringParser( strQueryString , arrName, arrValue)

nCount = 0
DO UNTIL arrName(nCount) = ""
          Response.Write arrName(nCount) & " : " & arrValue(nCount) & "<br>"
          nCount = nCount + 1
LOOP

결과 >
1 : a
2 : b
3 : c
반응형

+ Recent posts