* Unbounded String to string @ 2010-06-29 14:28 tonyg 2010-06-29 14:33 ` Adam Beneschan 2010-07-01 7:18 ` Jerry 0 siblings, 2 replies; 7+ messages in thread From: tonyg @ 2010-06-29 14:28 UTC (permalink / raw) Hi, I have an unbounded string from a database I want to turn into a 16 character subtype of string i.e. unbounded_string to string(1..16) I've been trying to do this most of the afternoon but keep getting errors anyone know how ? Thanks ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Unbounded String to string 2010-06-29 14:28 Unbounded String to string tonyg @ 2010-06-29 14:33 ` Adam Beneschan 2010-06-29 14:37 ` tonyg 2010-07-01 7:18 ` Jerry 1 sibling, 1 reply; 7+ messages in thread From: Adam Beneschan @ 2010-06-29 14:33 UTC (permalink / raw) On Jun 29, 7:28 am, tonyg <tonytheg...@googlemail.com> wrote: > Hi, > I have an unbounded string from a database I want to turn into a 16 > character subtype of string > > i.e. unbounded_string to string(1..16) > > I've been trying to do this most of the afternoon but keep getting > errors > > anyone know how ? Declare a subtype to give string(1..16) a name; then call To_String (in Ada.Strings.Unbounded) and convert the function result to your subtype. E.g.: subtype String_Length_16 is string(1..16); V : String_Length_16; V := String_Length_16 (Ada.Strings.Unbounded.To_String (U)); -- Adam ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Unbounded String to string 2010-06-29 14:33 ` Adam Beneschan @ 2010-06-29 14:37 ` tonyg 2010-06-29 15:08 ` Ludovic Brenta 0 siblings, 1 reply; 7+ messages in thread From: tonyg @ 2010-06-29 14:37 UTC (permalink / raw) On 29 June, 15:33, Adam Beneschan <a...@irvine.com> wrote: > On Jun 29, 7:28 am, tonyg <tonytheg...@googlemail.com> wrote: > > > Hi, > > I have an unbounded string from a database I want to turn into a 16 > > character subtype of string > > > i.e. unbounded_string to string(1..16) > > > I've been trying to do this most of the afternoon but keep getting > > errors > > > anyone know how ? > > Declare a subtype to give string(1..16) a name; then call To_String > (in Ada.Strings.Unbounded) and convert the function result to your > subtype. E.g.: > > subtype String_Length_16 is string(1..16); > V : String_Length_16; > > V := String_Length_16 (Ada.Strings.Unbounded.To_String (U)); > > -- Adam Thanks Adam ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Unbounded String to string 2010-06-29 14:37 ` tonyg @ 2010-06-29 15:08 ` Ludovic Brenta 2010-06-29 15:19 ` Adam Beneschan 0 siblings, 1 reply; 7+ messages in thread From: Ludovic Brenta @ 2010-06-29 15:08 UTC (permalink / raw) tonyg wrote on comp.lang.ada: > On 29 June, 15:33, Adam Beneschan <a...@irvine.com> wrote: >> On Jun 29, 7:28 am, tonyg <tonytheg...@googlemail.com> wrote: > >>> Hi, >>> I have an unbounded string from a database I want to turn into a 16 >>> character subtype of string >>> >>> i.e. unbounded_string to string(1..16) >>> >>> I've been trying to do this most of the afternoon but keep getting >>> errors >>> >>> anyone know how ? > >> Declare a subtype to give string(1..16) a name; then call To_String >> (in Ada.Strings.Unbounded) and convert the function result to your >> subtype. E.g.: >> >> subtype String_Length_16 is string(1..16); >> V : String_Length_16; >> >> V := String_Length_16 (Ada.Strings.Unbounded.To_String (U)); That solution only works if U happens to contain exactly 16 characters, which is probably not the case if the database really contains unbounded strings (i.e. VARCHAR or similar). So what you probably need is something more elaborate along the lines of: function To_String_16 (U : Ada.Strings.Unbounded.Unbounded_String) return String_16 is Temp : constant String := Ada.Strings.Unbounded.To_String (U); Result : String_16; begin Ada.Strings.Fixed.Move (Source => Temp, Target => Result, Drop => Ada.Strings.Right, Justify => Ada.Strings.Left, Pad => Ada.Characters.Space); return Result; end To_String_16; (some parameters of Ada.Strings.Fixed.Move have defaults; I spelled all them out for clarity at the expense of conciseness). -- Ludovic Brenta. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Unbounded String to string 2010-06-29 15:08 ` Ludovic Brenta @ 2010-06-29 15:19 ` Adam Beneschan 2010-06-30 8:28 ` tonyg 0 siblings, 1 reply; 7+ messages in thread From: Adam Beneschan @ 2010-06-29 15:19 UTC (permalink / raw) On Jun 29, 8:08 am, Ludovic Brenta <ludo...@ludovic-brenta.org> wrote: > tonyg wrote on comp.lang.ada: > > > > > > > On 29 June, 15:33, Adam Beneschan <a...@irvine.com> wrote: > >> On Jun 29, 7:28 am, tonyg <tonytheg...@googlemail.com> wrote: > > >>> Hi, > >>> I have an unbounded string from a database I want to turn into a 16 > >>> character subtype of string > > >>> i.e. unbounded_string to string(1..16) > > >>> I've been trying to do this most of the afternoon but keep getting > >>> errors > > >>> anyone know how ? > > >> Declare a subtype to give string(1..16) a name; then call To_String > >> (in Ada.Strings.Unbounded) and convert the function result to your > >> subtype. E.g.: > > >> subtype String_Length_16 is string(1..16); > >> V : String_Length_16; > > >> V := String_Length_16 (Ada.Strings.Unbounded.To_String (U)); > > That solution only works if U happens to contain exactly 16 > characters, which is probably not the case if the database really > contains unbounded strings (i.e. VARCHAR or similar). Right, when the OP said he wanted to "turn [an unbounded string] into a 16 character subtype", I didn't look more deeply into the words "turn into". I suppose I should have. We'd need to know exactly what his requirements are to provide a full solution, though--- specifically, does he expect any unbounded strings to be shorter than 16 characters, does he expect any of them to be longer than 16 characters, and if either or both is "yes", what it the desired behavior in each case. -- Adam ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Unbounded String to string 2010-06-29 15:19 ` Adam Beneschan @ 2010-06-30 8:28 ` tonyg 0 siblings, 0 replies; 7+ messages in thread From: tonyg @ 2010-06-30 8:28 UTC (permalink / raw) On 29 June, 16:19, Adam Beneschan <a...@irvine.com> wrote: > On Jun 29, 8:08 am, Ludovic Brenta <ludo...@ludovic-brenta.org> wrote: > > > > > > > tonyg wrote on comp.lang.ada: > > > > On 29 June, 15:33, Adam Beneschan <a...@irvine.com> wrote: > > >> On Jun 29, 7:28 am, tonyg <tonytheg...@googlemail.com> wrote: > > > >>> Hi, > > >>> I have an unbounded string from a database I want to turn into a 16 > > >>> character subtype of string > > > >>> i.e. unbounded_string to string(1..16) > > > >>> I've been trying to do this most of the afternoon but keep getting > > >>> errors > > > >>> anyone know how ? > > > >> Declare a subtype to give string(1..16) a name; then call To_String > > >> (in Ada.Strings.Unbounded) and convert the function result to your > > >> subtype. E.g.: > > > >> subtype String_Length_16 is string(1..16); > > >> V : String_Length_16; > > > >> V := String_Length_16 (Ada.Strings.Unbounded.To_String (U)); > > > That solution only works if U happens to contain exactly 16 > > characters, which is probably not the case if the database really > > contains unbounded strings (i.e. VARCHAR or similar). > > Right, when the OP said he wanted to "turn [an unbounded string] into > a 16 character subtype", I didn't look more deeply into the words > "turn into". I suppose I should have. We'd need to know exactly what > his requirements are to provide a full solution, though--- > specifically, does he expect any unbounded strings to be shorter than > 16 characters, does he expect any of them to be longer than 16 > characters, and if either or both is "yes", what it the desired > behavior in each case. > > -- Adam I never knew either way and its the first time I have been taking a string from a database - believe it or not all the rest have been numbers up to now :) but thanks to the both of you for your help. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Unbounded String to string 2010-06-29 14:28 Unbounded String to string tonyg 2010-06-29 14:33 ` Adam Beneschan @ 2010-07-01 7:18 ` Jerry 1 sibling, 0 replies; 7+ messages in thread From: Jerry @ 2010-07-01 7:18 UTC (permalink / raw) On Jun 29, 7:28 am, tonyg <tonytheg...@googlemail.com> wrote: > Hi, > I have an unbounded string from a database I want to turn into a 16 > character subtype of string > > i.e. unbounded_string to string(1..16) > > I've been trying to do this most of the afternoon but keep getting > errors > > anyone know how ? > > Thanks Check out Head, Tail, and possibly Trim. Jerry ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2010-07-01 7:18 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2010-06-29 14:28 Unbounded String to string tonyg 2010-06-29 14:33 ` Adam Beneschan 2010-06-29 14:37 ` tonyg 2010-06-29 15:08 ` Ludovic Brenta 2010-06-29 15:19 ` Adam Beneschan 2010-06-30 8:28 ` tonyg 2010-07-01 7:18 ` Jerry
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox