zoukankan      html  css  js  c++  java
  • 请问如何获取字符串在数组中的位置

    <%
    a="abc|ab|efg|hi"
    b="ab"
    response.write "b在a中的位置是"&getN(a,b)
    %>
    <%
    function getN(x,y)
    getN=0
    arr=split(x,"|")
    for i=0 to ubound(arr)
    if arr(i)=y then
    getN=i+1
    exit function
    end if
    next
    end function
    %>

    再给你一个:

    VBScript code
    '查询是否存在该值 Function seekArrayVal(strArr,strVal) Dim strBool:strBool=false If Not IsArray(strArr) Or strVal="" then seekArrayVal=strBool For Each tmp in strArr If strVal=tmp then strBool=true Exit For End If Next seekArrayVal=strBool End Function
    功能函数 
    -------------------------------------------------------
    function getposition(xstr,keyword)
    dim sw, k, ar
    dim i
    i=0
    sw=xstr
    k=keyword
    ar=split(sw,"|")
    do while i <ar.ubound(ar)-1
      if ar[i]=k then
          getposition=i
          exit function
      end if
      i=i+1
    loop
    end function
    -------------------------------------------------------
    a="abc|ab|efg|hi"
    有个字符串b ,b="ab"
    数组操作 a=split(a,"|")
    获取字符串b在数组a中的位置

    应用:
    dim posi
    posi=getposition(a,b)

  • 相关阅读:
    弹飞绵羊
    POJ 3308
    狼抓兔子
    块状链表题*1
    块状链表
    双向链表
    Linux入职基础-1.2_U盘安装RedHat5具体步骤
    Linux入职基础-1.1_国内开源的主要镜像站
    VS.NET(C#)--2.9_HTML服务器控件案例
    VS2015按钮方法
  • 原文地址:https://www.cnblogs.com/y0umer/p/3839461.html
Copyright © 2011-2022 走看看