Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 10 of 10 total
Thread substrings
Fri, May 20 2011 5:49 AMPermanent Link

Thor Warberg

I have a table containing a field (string) with measures like "34x55",
- designed in belief that this is easy to split up into 3 fields later if necessary.
I know, I have done something similar once - but it is some years ago. Now
I have not been programming for a long time.

Now I cannot find the code, neither on my pc or in this forum.
(DBISAM 3.26 and Delphi 7)
Any suggestions?
Thor W - Norway
Fri, May 20 2011 5:52 AMPermanent Link

Thor Warberg

Thor Warberg wrote:

Forgot one thing: the splitting has to focus on "x" - since the length differs, 1 ,2 or 3 digits.
Thor W - Norway
Fri, May 20 2011 8:40 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Thor


What you haven't said is wether you mean split into three fields in the table or just for use, and if the latter in SQL or Delphi code.

For now I'll assume you don't mean restructuring the table so:

for Delphi use this function

function SubFld(const InputString: string; const Separator: Char; const FieldNumber: integer): string;
var
Testing: integer;
FieldStart: integer;
CurrentField: integer;
begin
Testing := 1;
FieldStart := Testing;
CurrentField := 1;
while (Testing <= length(InputString)) do begin
 if InputString[Testing] = Separator then begin
  inc(CurrentField);
  if CurrentField > FieldNumber then break else FieldStart := Testing + 1;
 end;
 inc(Testing);
end;
if CurrentField >= FieldNumber then Result := copy(InputString, FieldStart, Testing - FieldStart) else Result := '';
end;


For SQL

SUBSTRING(field,1,POS('x',field)-1)

and

SUBSTRING(field,POS('x',field)+1,LENGTH(field))

I'm not certain wether V3 has SUBSTRING but I think it does.

Roy Lambert [Team Elevate]
Fri, May 20 2011 10:54 AMPermanent Link

Thor Warberg

Roy Lambert wrote:

Thor


What you haven't said is wether you mean split into three fields in the table or just for use, and if the latter in SQL or Delphi code.
@@ Dear Roy.
Sorry for beiing unprecise,
a) split one field into 3 fields is my intention.  
b) SQL or Delphi code - does not matter.

I wrote
SELECT ID, Tittel, SUBSTRING(Maal, POS,('x', Maal-1) FROM Register

but got error 11949:
FROM keyword expected after first SUBSTRING function argument,
instead found ',' in source column expression"

Sincerely
Thor

For now I'll assume you don't mean restructuring the table so:

for Delphi use this function

function SubFld(const InputString: string; const Separator: Char; const FieldNumber: integer): string;
var
Testing: integer;
FieldStart: integer;
CurrentField: integer;
begin
Testing := 1;
FieldStart := Testing;
CurrentField := 1;
while (Testing <= length(InputString)) do begin
 if InputString[Testing] = Separator then begin
  inc(CurrentField);
  if CurrentField > FieldNumber then break else FieldStart := Testing + 1;
 end;
 inc(Testing);
end;
if CurrentField >= FieldNumber then Result := copy(InputString, FieldStart, Testing - FieldStart) else Result := '';
end;


For SQL

SUBSTRING(field,1,POS('x',field)-1)

and

SUBSTRING(field,POS('x',field)+1,LENGTH(field))

I'm not certain wether V3 has SUBSTRING but I think it does.

Roy Lambert [Team Elevate]
Fri, May 20 2011 11:18 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Thor

Was there a reason you left a bracket out?

SELECT ID, Tittel, SUBSTRING(Maal, POS,('x', Maal)-1) FROM Register

Roy Lambert [Team Elevate]


Fri, May 20 2011 11:41 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Thor

You also missed the 1 - sorry I should have spotted that before

SELECT ID, Tittel, SUBSTRING(Maal,1,  POS,('x', Maal)-1) FROM Register

Roy Lambert [Team Elevate]

Fri, May 20 2011 4:14 PMPermanent Link

Thor Warberg

Roy Lambert wrote:

Thor

You also missed the 1 - sorry I should have spotted that before

SELECT ID, Tittel, SUBSTRING(Maal,1,  POS,('x', Maal)-1) FROM Register

Roy Lambert [Team Elevate]
@@@@
Roy

My code is identic with yours. (unfortunately not in the message)
The error message is exactly the same.
DBISAM 3 Manual has no entry for SUBSTRING under SQL.
(Neither does it appear in the List of Unsupported Language Elements.)
Are we at the end of sql-approach?
b) Delphi code - will that be able to split   
23x45,5      into 2 fields with     23 - 45
125,5x80                             125,5 - 80
etc.
Thor

Thor
Sat, May 21 2011 7:42 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Thor


I'm puzzled by that. I've just had a search through my newsgroup archive and I found a post relating to 2.11 and SUBSTRING. I can't help any more becuase I don't have V3.

Roy Lambert [Team Elevate]
Sun, May 22 2011 12:06 PMPermanent Link

Rita Tipton



"Thor Warberg" wrote in message
news:B0CE1BE7-6039-4225-9692-A1CC04F2F4BD@news.elevatesoft.com...

I have a table containing a field (string) with measures like "34x55",
- designed in belief that this is easy to split up into 3 fields later if
necessary.
I know, I have done something similar once - but it is some years ago. Now
I have not been programming for a long time.

Now I cannot find the code, neither on my pc or in this forum.
(DBISAM 3.26 and Delphi 7)
Any suggestions?
Thor W - Norway

################################################################

sA, sB:string;
//Simple parsing

if pos('x',Table1.FieldByName('YourField').AsString) = 3 then
  begin
  sA :=  copy(Table1.FieldByName('YourField').AsString,1,2);
  sB :=  copy(Table1.FieldByName('YourField').AsString,4,2);
end;


if  you have measures like 1x2 and 100x100 just make it a block of ifs

Then of course you would need to write the sA and sB to your table.
I use that method myself to parse out either side of racing SP's
so I can get sA and sB from the string to divide into a float.
HTH
Rita
Mon, May 23 2011 8:44 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Thor,

<< The error message is exactly the same.  DBISAM 3 Manual has no entry for
SUBSTRING under SQL.  >>

It should be under the SQL functions section.

The problem with your SQL is that DBISAM 3.x uses the long-form for both
SUBSTRING and POS:

SELECT ID, Tittel, SUBSTRING(Maal FROM 1 FOR POS('x' IN Maal)-1) FROM
Register

Notice the use of the FROM, FOR, and IN keywords.

--
Tim Young
Elevate Software
www.elevatesoft.com
Image