PowerBuilder Function Parse To Array gf_parse_to_array
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
///////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Function Name : gf_parse_to_array // Argument Name : as_source, Arg Type : String, Pass By : Value // as_delimiter, Arg Type : String, Pass By : Value // as_array[], Arg Type : String, Pass By : Reference // Return Type : Long /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Description: Parse a string into array elements using a delimeter string. /////////////////////////////////////////////////////////////////////////////////////////////////////////////// Long ll_DelLen Long ll_Pos Long ll_Count Long ll_Start Long ll_Length String ls_holder //Check for NULL If IsNull(as_source) Or IsNull(as_delimiter) Then Long ll_null SetNull(ll_null) Return ll_null End If //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 ++ as_Array[ll_Count] = ls_holder //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++ as_Array[ll_Count] = ls_holder End If //Return the number of entries found Return ll_Count |
Good Luck!
Subscribe
Login
0 Comments
Oldest