String Parsing Question

I am needing some advice from the Delphi experts. I have a program that will read an ascii string into a serial buffer. I need to be able to parse sections of the string and place them in to a TLabel. The string has spaces and I have not be able to find any information on the net about parsing a string with spaces. Here is an example of a string that I'm wanting to parse.

>2/14/07 23:00:25 Station - 4 Unit - 1 Command : Responding^M^J

> Command : PA off^M^J

What I would like to be able to do is take the date 2/14/07 and place it in a TLabel. Then take the time and do the same thing ect. ect. The ^M and ^J is a CR and LF. Does anyone have and recommendations on how I could parse out a string such as this?

Thank you,

Craig

Comments

  • : I am needing some advice from the Delphi experts. I have a program
    : that will read an ascii string into a serial buffer. I need to be
    : able to parse sections of the string and place them in to a TLabel.
    : The string has spaces and I have not be able to find any information
    : on the net about parsing a string with spaces. Here is an example of
    : a string that I'm wanting to parse.
    :
    : >2/14/07 23:00:25 Station - 4 Unit - 1 Command : Responding^M^J
    :
    : > Command : PA off^M^J
    :
    : What I would like to be able to do is take the date 2/14/07 and
    : place it in a TLabel. Then take the time and do the same thing ect.
    : ect. The ^M and ^J is a CR and LF. Does anyone have and
    : recommendations on how I could parse out a string such as this?
    :
    : Thank you,
    :
    : Craig


    Well i'm not sure what the parse word mean but if it is a string and i understand that you want to extract parts of a string out and paste it to another than the following will help:

    (stringtocopyfrom,positiontocopyfrom,howmanyspacestocopy) function

    Example:


    Procedure Parseform.ParseStringtolables();
    Var
    Position1,Character_to_copy : Integer;
    ParseString : String;

    Begin
    //Obtain value for the Parsestring variable here then for your problem the following code

    Characters_to_copy := Pos(' ',ParseString);
    Lbldate.caption := copy(ParseString,1,POsition,Characters_to_Copy);
    Delete(ParseString,1,Characters_to_copy+1);//Delete the date out of the string
    Characters_to_copy := Pos(' ',ParseString);
    LblTime.Caption := Copy(ParseString,1,Characters_to_copy);
    Delete(ParseString,1,Characters_to_copy+1);
    ect...
    End;

    Let me know if i was correct please
    Good luck

    SimonPRG
  • : : I am needing some advice from the Delphi experts. I have a program
    : : that will read an ascii string into a serial buffer. I need to be
    : : able to parse sections of the string and place them in to a TLabel.
    : : The string has spaces and I have not be able to find any information
    : : on the net about parsing a string with spaces. Here is an example of
    : : a string that I'm wanting to parse.
    : :
    : : >2/14/07 23:00:25 Station - 4 Unit - 1 Command : Responding^M^J
    : :
    : : > Command : PA off^M^J
    : :
    : : What I would like to be able to do is take the date 2/14/07 and
    : : place it in a TLabel. Then take the time and do the same thing ect.
    : : ect. The ^M and ^J is a CR and LF. Does anyone have and
    : : recommendations on how I could parse out a string such as this?
    : :
    : : Thank you,
    : :
    : : Craig
    :
    :
    : Well i'm not sure what the parse word mean but if it is a string and
    : i understand that you want to extract parts of a string out and
    : paste it to another than the following will help:
    :
    : (stringtocopyfrom,positiontocopyfrom,howmanyspacestocopy) function
    :
    : Example:
    :
    :
    : Procedure Parseform.ParseStringtolables();
    : Var
    : Position1,Character_to_copy : Integer;
    : ParseString : String;
    :
    : Begin
    : //Obtain value for the Parsestring variable here then for your
    : problem the following code
    :
    : Characters_to_copy := Pos(' ',ParseString);
    : Lbldate.caption := copy(ParseString,1,POsition,Characters_to_Copy);
    : Delete(ParseString,1,Characters_to_copy+1);//Delete the date out
    : of the string
    : Characters_to_copy := Pos(' ',ParseString);
    : LblTime.Caption := Copy(ParseString,1,Characters_to_copy);
    : Delete(ParseString,1,Characters_to_copy+1);
    : ect...
    : End;
    :
    : Let me know if i was correct please
    : Good luck
    :
    : SimonPRG

    Thank you Simon for the reply, Yes, basically what I want to do is take each word (ex. date) and place it into say TLable1 and the time into TLable2 ect. The strings vary in size depending on the call. But I want to be able to take each word and place it on it's own TLabel. I will give the code a try and let you know how it works out. again, thank you for the help.

    Craig
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories