• A little stringing along

    From Sean Dennis@1:18/200 to All on Tuesday, May 04, 2010 23:12:47
    Hello, All.

    I'm working on adding support for the GTUSER.BBS dropfile into my line of BBS doors. GTUSER.BBS, if you don't know, is a text file containing a single string that is broken up into several parts seperated by spaces. Don't laugh, but I've never quite gotten down the "searching in the strings" stuff. I guess
    I was spoiled by the MID$ command in BASIC all those years ago. :)

    Here's an example given to me by a GT Power sysop (this is all on a single line
    when read in; there is a space between the last name and the "SY"):

    === Cut ===
    A Daryl Stout SY,SH,KL,DR,DN,UP,PR,MS,MV,CC,RC,PW,CU,QK,MB,MU,CB,TB=05/05/02/01/03/01/01/60/6 0:120/120 LOCAL ANSI 5-4-10 480 307 18:53
    === Cut ===

    What I'm wanting to do is this: I want to start at the beginning of the line and read each "block" that's delimited by spaces into a string, so I can put the last name in one string, the first name in one string, the graphics type in
    another string, the DCE rate in another, so on and so forth. All data will be treated as strings and this will be read from a text file, so it's pretty easy to get the data in.

    I just am trying to figure out how to parse it correctly!

    Any help is appreciated.

    Thanks,
    Sean

    //sean@nsbbs.info | http://nsbbs.info | ICQ: 19965647

    ... Celibacy is NOT hereditary.
    --- GoldED/2 3.0.1
    * Origin: Nocturnal State BBS - (423) 926-7999 - bbs.nsbbs.info (1:18/200)
  • From Gene Buckle@1:138/142 to Sean Dennis on Wednesday, May 05, 2010 10:41:03
    Re: A little stringing along
    By: Sean Dennis to All on Tue May 04 2010 11:12 pm

    I just am trying to figure out how to parse it correctly!

    Any help is appreciated.


    Sean, try this routine:

    function GetField(Field : string; Delimiter : char; Position : integer) : string;
    var
    temp : string;
    i : integer;
    dPos : integer;

    begin
    dPos := 0;
    for i := 0 to Position do begin
    dPos := CharIPos(Field, Delimiter);
    if i <> Position then begin
    temp := StrMid(Field, dPos + 1, Length(temp));
    end;
    end;

    if dpos = 0 then
    Result := StrMid(temp, 1, Length(temp))
    else
    Result := StrMid(temp, 1, dPos -1);

    end;

    You'd call it like this:

    value := GetField(dropfile_string,' ',field_id);

    g.

    --- SBBSecho 2.12-Win32
    * Origin: The Retro Archive (1:138/142)
  • From Sean Dennis@1:18/200 to Gene Buckle on Wednesday, May 05, 2010 20:45:15
    Hello, Gene.

    Wednesday May 05 2010 at 10:41, you wrote to me:

    Sean, try this routine:

    Thanks, Gene, but is that straight Turbo Pascal? I didn't see a CharIPos or StrMid command anywhere in there.

    Later,
    Sean

    //sean@nsbbs.info | http://nsbbs.info | ICQ: 19965647

    ... Money may buy friendship but money cannot buy love.
    --- GoldED/2 3.0.1
    * Origin: Nocturnal State BBS - (423) 926-7999 - bbs.nsbbs.info (1:18/200)
  • From Gene Buckle@1:138/142 to Sean Dennis on Thursday, May 06, 2010 09:14:33
    Re: A little stringing along
    By: Sean Dennis to Gene Buckle on Wed May 05 2010 08:45 pm

    Hello, Gene.

    Wednesday May 05 2010 at 10:41, you wrote to me:

    Sean, try this routine:

    Thanks, Gene, but is that straight Turbo Pascal? I didn't see a CharIPos or StrMid command anywhere in there.

    Later,
    Sean

    //sean@nsbbs.info | http://nsbbs.info | ICQ: 19965647

    ... Money may buy friendship but money cannot buy love.

    That came from a Delphi 7 project I worked on years ago. I've never tested it under TP, but even if it doesn't work right off, it's a good place to start. :)

    g.

    --- SBBSecho 2.12-Win32
    * Origin: The Retro Archive (1:138/142)
  • From mark lewis@1:3634/12 to Sean Dennis on Thursday, May 06, 2010 12:54:36

    What I'm wanting to do is this: I want to start at the beginning of
    the line and read each "block" that's delimited by spaces into a
    string, so I can put the last name in one string, the first name in
    one string, the graphics type in another string, the DCE rate in
    another, so on and so forth. All data will be treated as strings
    and this will be read from a text file, so it's pretty easy to get
    the data in.

    here's something i had laying around... the original used a ';' as a divider with #32 and #9... i just changed the ';' to ',' so it would break out all of the comma delimited fields as well... it is the 3rd "str[i]" in each of the three while lines...


    program extract_word_test;

    const
    t1_str : string = 'A Daryl Stout SY,SH,KL,DR,DN,UP,';
    t2_str : string = 'PR,MS,MMV,CC,RC,PW,CU,QK,MB,MU,CB,';
    t3_str : string = 'TB=05/05/02/01/03/01/01/60/60:120/120 ';
    t4_str : string = 'LOCAL ANSI 5-4-10 4880 307 18:53';

    var
    my_cnt : integer;
    my_str,
    result_str : string;

    function extractword(str : string; n : integer) : string;
    var
    count : integer;
    i : integer;
    len : integer;
    done : boolean;
    retstr : string;

    begin
    retstr := '';
    len := length(str);
    count := 0;
    i := 1;
    done := false;
    while (i <= len) and (not done) do
    begin
    while ((i <= len) and
    ((str[i] = #32) or
    (str[i] = #9) or
    (str[i] = ','))) do
    inc(i);
    if i <= len then
    inc(count);
    if count = n then
    begin
    retstr[0] := #0;
    if (i > 1) then
    if str[i-1] = ';' then
    retstr := ';';
    while ((i <= len) and
    ((str[i] <> #32) and
    (str[i] <> #9) and
    (str[i] <> ','))) do
    begin
    inc(retstr[0]);
    retstr[ord(retstr[0])] := str[i];
    inc(i);
    end;
    done := true;
    end
    else
    while ((i <= len) and
    ((str[i] <> #32) and
    (str[i] <> #9) and
    (str[i] <> ','))) do
    inc(i);
    end;
    extractword := retstr;
    end;

    begin
    my_str := t1_str + t2_str + t3_str + t4_str;
    writeln(my_str);
    for my_cnt := 0 to 28 do
    begin
    result_str := extractword(my_str,my_cnt);
    writeln(my_cnt, ' : ''',result_str,'''');
    end;
    end.


    * Origin: (1:3634/12)
  • From Sean Dennis@1:18/200 to mark lewis on Thursday, May 06, 2010 19:34:31
    Hello, mark.

    Thursday May 06 2010 at 12:54, you wrote to me:

    (after tinkering with the code a bit)

    here's something i had laying around... the original used a ';' as a divider with #32 and #9... i just changed the ';' to ',' so it would
    break out all of the comma delimited fields as well... it is the 3rd "str[i]" in each of the three while lines...

    I actually want to skip over that entire comma-delimited section. I just am going to pull the first and last name, DCE rate, time left and ANSI toggle for my needs. I'll do a little more tinkering and thanks for the code; I think I'll get it to do what I need it to do. :)

    Later,
    Sean

    //sean@nsbbs.info | http://nsbbs.info | ICQ: 19965647

    ... Trouble is only opportunity in work clothes. - Henry J. Kaiser
    --- GoldED/2 3.0.1
    * Origin: Nocturnal State BBS - (423) 926-7999 - bbs.nsbbs.info (1:18/200)
  • From Sean Dennis@1:18/200 to Gene Buckle on Thursday, May 06, 2010 19:18:55
    Hello, Gene.

    Thursday May 06 2010 at 09:14, you wrote to me:

    That came from a Delphi 7 project I worked on years ago. I've never tested it under TP, but even if it doesn't work right off, it's a good place to start. :)

    Yep. I thought that was Delphi. :)

    Thanks for the code.

    Later,
    Sean

    //sean@nsbbs.info | http://nsbbs.info | ICQ: 19965647

    ... On y soit, qui mal y pense. (You are what you think.)
    --- GoldED/2 3.0.1
    * Origin: Nocturnal State BBS - (423) 926-7999 - bbs.nsbbs.info (1:18/200)
  • From Sean Dennis@1:18/200 to mark lewis on Thursday, May 06, 2010 19:19:14
    Hello, mark.

    Thursday May 06 2010 at 12:54, you wrote to me:

    here's something i had laying around... the original used a ';' as a divider with #32 and #9... i just changed the ';' to ',' so it would
    break out all of the comma delimited fields as well... it is the 3rd "str[i]" in each of the three while lines...

    Now would this work with a single line to run through it? GTUSER.BBS is a single line that's passed as a text file. I'll give this a shot this weekend though. Thanks for the code!

    Later,
    Sean

    //sean@nsbbs.info | http://nsbbs.info | ICQ: 19965647

    ... Got my tie caught in the fax -- suddenly I was in L.A....
    --- GoldED/2 3.0.1
    * Origin: Nocturnal State BBS - (423) 926-7999 - bbs.nsbbs.info (1:18/200)
  • From mark lewis@1:3634/12 to Sean Dennis on Friday, May 07, 2010 10:00:01

    (after tinkering with the code a bit)

    here's something i had laying around... the original used a ';' as a divider with #32 and #9... i just changed the ';' to ',' so it would
    break out all of the comma delimited fields as well... it is the 3rd "str[i]" in each of the three while lines...

    I actually want to skip over that entire comma-delimited section.

    ok, in that case, replace that ',' back with ';' as it was before i made that change... that'll pull out the 10 space delimited fields there are... i'm sure you've already found that the field count is 1 based and that it returns the empty string for non-existant fields... you can make it zero based by changing "count := 0;" to "count := -1;" ;)

    I just am going to pull the first and last name, DCE rate, time
    left and ANSI toggle for my needs.

    what's the field breakdown on that format? i was unable to locate anything in my library... i thought i had some gtuser code around here but i can't find it... i did find a bunck of stuff i have from joel bergen, though :P

    i'm not sure what field 1 is... 2 and 3 are obviously the first and last name... i don't see a DCE rate in there unless that's the "LOCAL" field...time left must be field 9... 10 would probably be the current time with 7 being the current date... no clue on "4880" in field 8...

    I'll do a little more tinkering and thanks for the code; I think
    I'll get it to do what I need it to do. :)

    not a problem... IIRC, that actually came from one of mark may's libraries ;)

    )\/(ark


    * Origin: (1:3634/12)
  • From mark lewis@1:3634/12 to Sean Dennis on Friday, May 07, 2010 10:15:19

    here's something i had laying around... the original used a ';' as a divider with #32 and #9... i just changed the ';' to ',' so it would
    break out all of the comma delimited fields as well... it is the 3rd "str[i]" in each of the three while lines...

    Now would this work with a single line to run through it?

    yes... i took the sample line you posted and made it couple of constants... you
    should be able to do the file read to pull the line into a var and send it to extractword... i only did the constant to make it easier for the demo and broke
    it up into pieces for readability ;)

    GTUSER.BBS is a single line that's passed as a text file. I'll
    give this a shot this weekend though. Thanks for the code!

    :)

    )\/(ark


    * Origin: (1:3634/12)
  • From John Guillory@1:135/364 to Sean Dennis on Wednesday, June 16, 2010 21:26:56
    °·. Regarding : A little stringing along .·°
    °·. Reply Requested? Yes, Please Reply. .·°

    ┌──°·. Sean Dennis whispered this to mark lewis...
    │ I actually want to skip over that entire comma-delimited section. I just am │ going to pull the first and last name, DCE rate, time left and ANSI toggle fo │ my needs. I'll do a little more tinkering and thanks for the code; I think I │ get it to do what I need it to do. :)
    └──.·° Out of the stillness, john guillory said this...

    In that case, on my previous post, remove the line that has the POS(',',ST)
    in it...

    POS(' ',ST) Returns an integer to the point in the string where the
    ' ' is found at....
    Copy(ST,1,x) Copies x characters from string ST starting at character
    #1 ....
    Delete(St,1,x) Deletes x characters from string ST starting at position
    1....

    Thus Copy(St,1,Pos(' ',ST)-1) Copies from the beginning to before the space. and Delete(St,1,Pos(' ',ST)) Deletes that field from string ST and the ' '.

    Store the field and repeat to get the rest of the strings, basic CSV
    format without commas....

    --- Virtual Advanced Ver 2 for DOS
    * Origin: Deep Space 69 BBS - telnet://ds69bbs.com - Florida (1:135/364)