您的位置:程序门 -> vb -> 基础类



vb提取字符串中的数字


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


vb提取字符串中的数字[已结贴,结贴人:xy_wolf]
发表于:2007-05-09 18:38:52 楼主
vb中如何实现以下字符串分解
0.3mm
  ≤123v
5mn
只要数字和小数点~~~~~
发表于:2007-05-09 20:15:371楼 得分:5
dim   a()   as   string
dim   acount   as   integer
dim   i   as   integer
'你的字符串
dim   strx   as   string
dim   a_num   as   boolean

acount   =   1
redim   preserve   a(1   to   acount)
for   i   =   1   to   len(strx)
        if   (asc(mid(strx,   i,   1))   > =   48   and   asc(mid(strx,   i,   1))   <=   57)   _
                or   asc(mid(strx,   i,   1))   =   46   then
              a(acount)   =   a(acount)   &   mid(strx,   i,   1)
              if   a_num   =   false   then
                    a_num   =   true
              end   if
        else
              if   a_num   =   true   then
                    acount   =   acount   +   1
                    redim   preserve   a(1   to   acount)
                    a_num   =   false
              end   if
        end   if
next   i

那些数字放在a数组,一共acount个
发表于:2007-05-09 20:17:132楼 得分:5

字符串

qw123jknm234> 2349.23sdf43.43   safjk     sadf   1.023,sas

处理结果:

123         234         2349.23         43.43         1.023
发表于:2007-05-09 20:18:103楼 得分:0
利用正则表达式
发表于:2007-05-09 20:20:044楼 得分:0
正则表达式
发表于:2007-05-09 20:36:545楼 得分:0
正则表达式是net里面的东西!!
发表于:2007-05-09 20:53:506楼 得分:5
function   myget(srg   as   string,   optional   n   as   integer   =   false,   _
                        optional   start_num   as   integer   =   1)
          dim   i                 as   integer
          dim   s                 as   string
          dim   mystring   as   string
          dim   bol             as   boolean
       
          for   i   =   start_num   to   len(srg)
                  s   =   mid(srg,   i,   1)
                  if   n   =   1   then
                        bol   =   asc(s)   <   0                       '分離漢字
                  elseif   n   =   2   then
                        bol   =   s   like   "[a-z,a-z,   ] "   '分離字母
                  elseif   n   =   0   then
                        bol   =   s   like   "# "                       '分離數字
                  end   if
                  if   bol   then   mystring   =   mystring   &   s
          next
          myget   =   iif(n   =   1   or   n   =   2,   mystring,   val(mystring))
      end   function
发表于:2007-05-10 10:15:157楼 得分:5
这样简单点:

i=len(t)
do   while   i> =1
    if   (asc(mid(t,i,1)) <asc( "0 ")   or   asc(mid(t,i,1))> asc( "9 "))   and   asc(mid(t,i,1)) <> asc( ". ")   then   t=replace(t,mid(t,i,1), " ")
    i=i-1
loop
发表于:2007-05-10 10:20:368楼 得分:0
i=len(t)
do   while   i> =1
    if   (asc(mid(t,i,1)) <asc( "0 ")   or   asc(mid(t,i,1))> asc( "9 "))   and   asc(mid(t,i,1)) <> asc( ". ")   then   t=replace(t,mid(t,i,1), " ")
    i=i-1
    if   i> len(t)   then   i=len(t)
loop


快速检索

最新资讯
热门点击