当前位置: 代码迷 >> PB >> 从指定字符得到数量及值,该怎么解决
  详细解决方案

从指定字符得到数量及值,该怎么解决

热度:54   发布时间:2016-04-29 06:26:19.0
从指定字符得到数量及值
之前的都做不到呀!!
分割符号是“;”,大写的。


源数据“192.168;192.168.3;”,得到数量2及192.168与192.168.3 

源数据“192.168;192.168.3”,得到数量1及192.168与192.168.3 。只有一个分隔符号

源数据“192.168;192.168.3;192.168;192.168.3;”,得到数量2及192.168与192.168.3 并给出重复提示。重复的不计入统计。
以上是举例,源数据很长。但均有指定的分隔符号";",大写的。




------解决方案--------------------
数量是不是对分隔符的计数?重复值后的分隔符也不计数?


string ls_text, ls_break, ls_exists, ls_exists_right
string ls_subval, ls_aryindex 
long ll_pos, ll_pos2
string ls_result[] //存放结果值
long ll_result_count[] //存放结果值对应的计数
long ll_break_count //存放分隔符计数

ls_text = '192.168;192.168.3;192.168;192.168.3;'
ls_break = ';' //定义分隔符

do while true
if len(ls_text) <= 0 then exit
ll_pos = pos(ls_text, ls_break)
if ll_pos <= 0 then
ls_subval = ls_text
ls_text = ''
else
ls_subval = left(ls_text, ll_pos - 1)
ls_text = mid(ls_text, ll_pos + len(ls_break))
end if

ll_pos2 = pos(ls_exists, '[' + ls_subval + '
------解决方案--------------------
')
if ll_pos2 > 0 then
//重复
ls_exists_right = mid(ls_exists, ll_pos2 + len('[' + ls_subval + '
------解决方案--------------------
'))
//找到重复值在数组中的位置,更新计数器
ls_aryindex = left(ls_exists_right, pos(ls_exists_right, ']') - 1)
ll_result_count[long(ls_aryindex)] ++
else
//不重复
if ll_pos > 0 then ll_break_count ++
ls_result[upperbound(ls_result) + 1] = ls_subval
ll_result_count[upperbound(ls_result)] = 1
//把每个值对应在数组中的位置缓存起来,当值存在更新时无需去遍历数组,存放规则为[value
------解决方案--------------------
index]
ls_exists += '[' + ls_subval + '
------解决方案--------------------
' + string(upperbound(ls_result)) + ']'
end if
loop

//输出结果
messagebox('info', ll_break_count)

for ll_pos = 1 to upperbound(ls_result)
messagebox('info', "Value: " +  ls_result[ll_pos] + '~r~nCount: ' + string(ll_result_count[ll_pos]))
next

------解决方案--------------------

------解决方案--------------------

------解决方案--------------------
引用:
是我要得

做成函数调用.



/**********************
*定义函数             *
**********************/
global type gf_parse_string from function_object
end type

forward prototypes
global function long gf_parse_string (string as_text, string as_break, ref string as_result[], ref long al_result_count[])
end prototypes

global function long gf_parse_string (string as_text, string as_break, ref string as_result[], ref long al_result_count[]);string ls_exists, ls_exists_right
string ls_subval, ls_aryindex 
long ll_pos, ll_pos2
string ls_result[] //存放结果值
long ll_result_count[] //存放结果值对应的计数
long ll_break_count //存放分隔符计数

do while true
if len(as_text) <= 0 then exit
ll_pos = pos(as_text, as_break)
if ll_pos <= 0 then
ls_subval = as_text
as_text = ''
else
ls_subval = left(as_text, ll_pos - 1)
as_text = mid(as_text, ll_pos + len(as_break))
end if

ll_pos2 = pos(ls_exists, '[' + ls_subval + '
------解决方案--------------------
')
if ll_pos2 > 0 then
//重复
ls_exists_right = mid(ls_exists, ll_pos2 + len('[' + ls_subval + '
------解决方案--------------------
'))
//找到重复值在数组中的位置,更新计数器
ls_aryindex = left(ls_exists_right, pos(ls_exists_right, ']') - 1)
ll_result_count[long(ls_aryindex)] ++
else
//不重复
if ll_pos > 0 then ll_break_count ++
ls_result[upperbound(ls_result) + 1] = ls_subval
ll_result_count[upperbound(ls_result)] = 1
//把每个值对应在数组中的位置缓存起来,当值存在更新时无需去遍历数组,存放规则为[value
------解决方案--------------------
index]
ls_exists += '[' + ls_subval + '
------解决方案--------------------
' + string(upperbound(ls_result)) + ']'
end if
loop

as_result = ls_result
al_result_count = ll_result_count

return ll_break_count
end function
  相关解决方案