首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > PB >

PB中字符串操作有关问题

2013-03-22 
PB中字符串操作问题请教下,在PB中想对一个字符串(ASWQWD223A-WQW22QRR-233-1WWW331S0-EEWW22DDFER)做如下

PB中字符串操作问题
请教下,在PB中想对一个字符串(ASWQWD223A-WQW22QRR-233-1WWW331S0-EEWW22DDFER)做如下操作,改怎么解决:

1、把字符串变为EEWW22DDFER-1WWW331S0-233-WQW22QRR-ASWQWD223A
2、去除字符串中的字符'-',得到EEWW22DDFER1WWW331S0233WQW22QRRASWQWD223A
3、在得到的字符串前后分别加上ABCD和EFGH
最后得到ABCDEEWW22DDFER1WWW331S0233WQW22QRRASWQWD223AEFGH
最后对这串字符串进行MD5 32位加密

[解决办法]
送你两个函数,gf_string2arry,拆字符串进数组,你的要求1,可以用这个拆成数组后反向循环,连接。要求2用gf_replace替换连接符,后边的自己加吧。MD5的加密网上一把,自己搜吧。另外,你的结贴率,令人害怕

global type gf_string2arry from function_object
end type

forward prototypes
global function integer gf_string2arry (string as_parmstring, string as_string, ref string as_parm[])
end prototypes

global function integer gf_string2arry (string as_parmstring, string as_string, ref string as_parm[]);//------------------------------------------
// 描述: 将以传进的参数as_string作为分隔符的string型参数串as_parmstring分解成独立参数并放入变长数组
//------------------------------------------
// 参数: 
//  value     string as_parmstring  以as_string作分隔符的多参数组成的字符串(要求原始的string型独立参数内不得含有as_string字符)
//  value     string as_string      用与字符串中的分隔符号
//  reference string as_parm[]      存放分解后的独立参数
//------------------------------------------
// 返回值:  integer  成功,返回变量个数;否则,返回 -1
//------------------------------------------

integer li_finger,li_start=1,li_counter

if as_parmstring="" then return -1

li_finger=pos(as_parmstring,as_string,li_start)

do while li_finger>0
 li_counter ++
 as_parm[li_counter]=mid(as_parmstring,li_start,li_finger - li_start)
 li_start=li_finger + 1
 li_finger=pos(as_parmstring,as_string,li_start)
loop

if li_start<=len(as_parmstring) then
 li_counter ++
 as_parm[li_counter]=mid(as_parmstring,li_start,len(as_parmstring) - li_start +1)
end if

return li_counter
end function



global type gf_replace from function_object
end type

forward prototypes
global function string gf_replace (string source, string look_for, string replace_with)
end prototypes

global function string gf_replace (string source, string look_for, string replace_with);//*********************************************************************
//* Program Id: [ ]
//* Function: 
//* Program By: PowerSoft
//* Windows: 
//* Data Windows:
//* Modification 
//* Description: A String Occurrence Search and Replace Routine
//*The following code demonstrates a string occurrence search and replace routine.
//*This routine works generically for any string. For example, 
//*if old_str = "red" and new_str = "green", all occurrences of 
//* "red" inside of mystring will be replaced with "green".


//*********************************************************************


Int start_pos=1,len_look_for

len_look_for = len(look_for)

//find the first occurrence of look_for ...
start_pos = Pos(source,look_for,start_pos)

//only enter the loop if you find whats in look_for

DO WHILE start_pos > 0
//replace look_for with replace_with ...
source = Replace(source,start_pos,Len_look_for,replace_with)
//find the next occurrence of look_for
start_pos = Pos(source,look_for,start_pos+Len(replace_with))
LOOP
return source



end function

热点排行