请教问题:pb9.0如何分割字符串

asdfgh2009 2013-07-08 10:22:21
字符串1524s/abc/dfe/dsfd/kii,如何通过程序实现这个效果,麻烦高手,指导一下,能否举例说明,谢谢了。
...全文
650 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Doane 2013-07-09
  • 打赏
  • 举报
回复
给你一个字符串转数组的函数看看,道理一样的:
//////////////////////////////////////////////////////////////////////////////
//
//	Function:  of_ParseToArray
//
//	Access:  public
//
//	Arguments:
//	as_Source   The string to parse.
//	as_Delimiter   The delimeter string.
//	as_Array[]   The array to be filled with the parsed strings, passed by reference.
//
//	Returns:  long
//	The number of elements in the array.
//	If as_Source or as_Delimeter is NULL, function returns NULL.
//
//	Description:  Parse a string into array elements using a delimeter string.
//
//////////////////////////////////////////////////////////////////////////////
long		ll_DelLen, ll_Pos, ll_Count, ll_Start, ll_Length
String 	ls_holder, ls_empty_array[]

//Check for NULL
IF IsNull(as_source) or IsNull(as_delimiter) Then
	long ll_null
	SetNull(ll_null)
	Return ll_null
End If

as_array = ls_empty_array

//Check for at leat one entry
If Trim (as_source) = '' Then
	Return 0
End If

//Get the length of the delimeter
ll_DelLen = Len(as_Delimiter)

ll_Pos =  Pos(Upper(as_source), Upper(as_Delimiter))

//Only one entry was found
if ll_Pos = 0 then
	as_Array[1] = as_source
	return 1
end if

//More than one entry was found - loop to get all of them
ll_Count = 0
ll_Start = 1
Do While ll_Pos > 0
	
	//Set current entry
	ll_Length = ll_Pos - ll_Start
	ls_holder = Mid (as_source, ll_start, ll_length)

	// Update array and counter
	ll_Count ++
	If ab_trim Then
		as_Array[ll_Count] = Trim(ls_holder)
	Else
		as_Array[ll_Count] = ls_holder
	End If
	
	//Set the new starting position
	ll_Start = ll_Pos + ll_DelLen

	ll_Pos =  Pos(Upper(as_source), Upper(as_Delimiter), ll_Start)
Loop

//Set last entry
ls_holder = Mid (as_source, ll_start, Len (as_source))

// Update array and counter if necessary
if Len (ls_holder) > 0 then
	ll_count++
	If ab_trim Then
		as_Array[ll_Count] = Trim(ls_holder)
	Else
		as_Array[ll_Count] = ls_holder
	End If
end if

//Return the number of entries found
Return ll_Count
jlwei888 2013-07-09
  • 打赏
  • 举报
回复
用pos来定位'/',然后left取出,剩下的串再次循环

740

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 脚本语言
社区管理员
  • 脚本语言社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧