From: Tsourinakis A. <ts...@ot...> - 2001-04-18 09:52:56
|
On Tue, 17 Apr 2001 19:54:19 +0000 (UTC), cv...@us... ("Claudio Valderrama C.") wrote: >Ok, please help me to shape what you want the UDF substring should do: >- When parameters are wrong: return NULL or empty string? Examples of wrong >parameters: starting pos less than zero. >- When final position is greater than the string's length, return from >initial pos up to the last character? I think that SUBSTR(s,n,m) must return if string is NULL then return NULL else if aritmetic parameters are wrong return EMPTY_STRING else return AS_MUCH_CHARACTERS_AS_YOU_CAN the code you send I think is as it must be. This is in pascal as I think that must work (I cannot catch the NULL) ====================== function Substring(s:string;m,n:integer):string;overload; var len :integer; begin len := length(s); if (len<1) or (m<1) or (n<1) or (m>len) then result:= '' //'EMPTY' else if m+n>len then result := copy(s,m,len-m+1) else result := copy(s,m,n) end; function Substring(s:string;m:integer):string;overload; var len :integer; begin len := length(s); if (len<1) or (m<1) or (m>len) then result:= '' //'EMPTY' else result := copy(s,m,len-m+1) end; ============== >- I understood that I should leave the current function's arguments as they >are: starting pos, final pos. Do I create a second UDF to handle the >pascal-style function, with starting pos and length of the slice as >arguments? > I think that is also a very good idea and name it SUBSTRING (as is more standard, see my previous answer). I don't know if it can be used with either 2 or 3 parameters. If I remember in C you can do such things) Antonis Tsourinakis Piraeus-Greece |