您的位置:程序门 -> web 开发 -> asp



这个字符串怎么转换?。。。。在线等


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


这个字符串怎么转换?。。。。在线等[已结贴,结贴人:t_88888888]
发表于:2007-05-24 08:55:05 楼主
字符串str= "s68001011-s68001015,s68002011,s68001186-s68001190,s68001041-s68001045 ";要将之中间的省略部分全部转换出来,比如str2= "s68001011,s68001012,s68001013,s68001014,s68001015,s68002011,s68001186,s68001187。。。。。。。 ",这样的函数该怎么写?
发表于:2007-05-24 09:20:241楼 得分:0
replace(s,   "- ",   ", ")


visual   basic   scripting   edition      

replace   函数
请参阅
filter   函数
要求
版本   2
返回字符串,其中指定数目的某子字符串被替换为另一个子字符串。

replace(expression,   find,   replacewith[,   compare[,   count[,   start]]])
参数
expression  
必选项。字符串表达式包含要替代的子字符串。  
find  
必选项。被搜索的子字符串。  
replacewith  
必选项。用于替换的子字符串。  
start  
可选项。expression   中开始搜索子字符串的位置。如果省略,默认值为   1。在和count   关联时必须用  
count  
可选项。执行子字符串替换的数目。如果省略,默认值为   -1,表示进行所有可能的替换。在和   start   关联时必须用。  
compare  
可选项。指示在计算子字符串时使用的比较类型的数值。有关数值,请参阅“设置”部分。如果省略,缺省值为   0   ,这意味着必须进行二进制比较。  
设置
compare   参数可以有以下值:

常数   值   描述  
vbbinarycompare   0   执行二进制比较。  
vbtextcompare   1   执行文本比较。  

返回值
replace   返回以下值:

如果   replace   返回  
expression   为零长度   零长度字符串   ( " ")。  
expression   为   null   错误。  
find   为零长度   expression   的副本。  
replacewith   为零长度   expression   的副本,其中删除了所有由   find   参数指定的内容。  
start   >   len(expression)   零长度字符串。  
count   为   0   expression   的副本。  

说明
replace   函数的返回值是经过替换(从由   start   指定的位置开始到   expression   字符串的结尾)后的字符串,而不是原始字符串从开始至结尾的副本。

下面的示例利用   replace   函数返回字符串:

dim   mystring
mystring   =   replace( "xxpxxpxxp ",   "p ",   "y ")       '二进制比较从字符串左端开始。返回   "xxyxxpxxy "。
mystring   =   replace( "xxpxxpxxp ",   "p ",   "y ",   '文本比较从第三个字符开始。返回   "yxxyxxy "。3,,   -1,   1)  
发表于:2007-05-24 09:30:322楼 得分:10
function   getseries(strcode)
    dim   arrlist
    dim   alist
    dim   strtmp
    dim   strt
    dim   strbegin,   strend,   strhead,   ibengin,   iend
    dim   i,   k
   
    if   strcode   =   " "   then
        getseries   =   " "
        exit   function
    end   if
   
    strcode   =   replace(strcode,   ", ",   ", ")
    arrlist   =   split(strcode,   ", ")
    if   isarray(arrlist)   then
          for   i   =   0   to   ubound(arrlist)
              strt   =   arrlist(i)
              if   instr(strt,   "- ")   then
                    alist   =   split(strt,   "- ")
                    strbegin   =   trim(alist(0))
                    strend   =   trim(alist(1))
                    strhead   =   left(strbegin,   1)
                    ibengin   =   right(strbegin,   len(strbegin)   -   1)
                    iend   =   right(strend,   len(strend)   -   1)
                    for   k   =   ibengin   to   iend
                        if   strtmp   =   " "   then
                            strtmp   =   strhead   &   cstr(k)
                        else
                            strtmp   =   strtmp   &   ", "   &   strhead   &   cstr(k)
                        end   if
                    next
              else
                    if   strtmp   =   " "   then
                          strtmp   =   strt
                    else
                          strtmp   =   strtmp   &   ", "   &   strt
                    end   if
              end   if
          next
    else
        getseries   =   " "
        exit   function
    end   if
   
    getseries   =   strtmp
end   function
发表于:2007-05-24 09:32:253楼 得分:0
这样不行的啊,是要展开,表示简单的替换,要判断“,”号来分隔,然后判断“-”来取出最大最小值,填充中间值。逻辑判断上比较难写啊
发表于:2007-05-24 09:38:594楼 得分:0
dim   i,j,str
                dim   outstr
                dim   temstr,   ntemstr
                dim   numb,   nume  

                temstr   =   split(str,   ", ")
                for   i   =   0   to   ubound(temstr)
                        ntemstr   =   " "
                        if   instr(temstr(i),   "- ")   >   0   then
                                ntemstr   =   split(temstr(i),   "- ")
                                numb   =   clng(replace(ntemstr(0),   "s ",   " "))
                                nume   =   clng(replace(ntemstr(ubound(ntemstr)),   "s ",   " "))
                                for   j   =   numb   to   nume
                                        outstr   =   outstr   &   ", "   &   "s "   &   cstr(j)
                                next
                        else
                                outstr   =   outstr   &   ", "   &   temstr(i)
                        end   if
                next
                outstr   =   mid(outstr,   2)
发表于:2007-05-24 09:40:455楼 得分:0
private   function   getstr(str)
                dim   i,j,str
                dim   outstr
                dim   temstr,   ntemstr
                dim   numb,   nume  

                temstr   =   split(str,   ", ")
                for   i   =   0   to   ubound(temstr)
                        ntemstr   =   " "
                        if   instr(temstr(i),   "- ")   >   0   then
                                ntemstr   =   split(temstr(i),   "- ")
                                numb   =   clng(replace(ntemstr(0),   "s ",   " "))
                                nume   =   clng(replace(ntemstr(ubound(ntemstr)),   "s ",   " "))
                                for   j   =   numb   to   nume
                                        outstr   =   outstr   &   ", "   &   "s "   &   cstr(j)
                                next
                        else
                                outstr   =   outstr   &   ", "   &   temstr(i)
                        end   if
                next
                getstr   =   mid(outstr,   2)
end   function
发表于:2007-05-24 09:44:376楼 得分:20
以上函数在vb.net   2005上测试通过,满足你的功能需求!
发表于:2007-05-24 09:50:437楼 得分:0
结贴,给分,谢谢teren2002,wangwm!
发表于:2007-05-24 10:38:458楼 得分:0
晕倒,还有个排序啊。。
<%
function   sort(a,   f)
dim   temp,   l,   i,   j   :   l   =   ubound(a)

for   i   =   0   to   l
if   eval( "int(a( "   &   i   +   1   &   "))   "   &   f   &   "int(a( "   &   i   &   ")) ")   then
j   =   i   +   1
do   while   eval( "int(a( "   &   j   &   "))   "   &   f   &   "int(a( "   &   j   -   1   &   ")) ")
temp   =   a(j)   :   a(j)   =   a(j   -   1)   :   a(j   -   1)   =   temp   :   j   =   j   -   1
if   j   =   0   then   exit   do
loop
end   if
if   i   +   1   =   l   then   exit   for
next
sort   =   a
end   function

dim   ary   :   ary   =   split(   _
replace(   _
replace( "s68001011-s68001015,s68002011,s68001186-s68001190,s68001041-s68001045 ",   "- ",   ", ")   _
,   "s ",   " ")   _
,   ", ")
response.write   "s "   &   join(sort(ary,   " < "),   ",s ")
%>
发表于:2007-05-24 10:41:149楼 得分:0
-   -
看来我看错了。。
闪了。


快速检索

最新资讯
热门点击