Delphi

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • Using the copy function to separate data

    0 answers - 4468 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    , then you need to change the third argument in the Copy funtion - it's the length of the returned string -
    like this - Copy(<string to copy>, <postion to start>, <length>)
    the same code with the third argument set to length (3) -
    procedure TfrmMain.Button1Click(Sender: T);
    var
    Data : string;
    begin
    Data := '0.0000.1370. 000';
    memo.lines.add( Copy (Data, 1, 3));
    memo.lines.add( Copy (Data, 6, 3));
    memo.lines.add( Copy (Data, 11, 3));
    end;
    Here's the result the new code gets:
    0.0
    0.1
    0.
    Notice, the third result still isn't what you want - that's because there's still a space in your data string. If you clean all the spaces out of the string, you'll get the right result (I trimmed the space from the front of the string when I first made the sample code).
    To get all those pesky spaces out, you can add a function - like this:
    procedure TfrmMain.Button1Click(Sender: T);
    function GetRSpaces(InString: String): string;
    var
    i: integer;
    begin
    Result := '';
    for i := 1 to Length(InString) do
    begin
    if InString[i] <' ' then Result := Result + InString[i];
    end;
    end;
    var
    Data : string;
    begin
    Data := '0.0000.1370. 000';
    Data := GetRSpaces(Data);
    memo.lines.add( Copy (Data, 1, 3));
    memo.lines.add( Copy (Data, 6, 3));
    memo.lines.add( Copy (Data, 11, 3));
    end;
    Here's the result you're looking for:
    0.0
    0.1
    0.0
    I hope this helps.
    joe
    Joe Wilcox
    "Reading Cliff Notes to know a novel is like eating Count Chocula to know steak"
    "Nine women cannot have a baby in one month"
    falon5000 (AT) yahoo (DOT) com
    Message
    From: Curtis cloud <curtiscld (AT) yahoo (DOT) com>
    To: delphi-en (AT) yahoogroups (DOT) com
    Sent: Thursday, January 4, 2007 8:23:05 PM
    Subject: Re: [delphi-en] Using the copy function to separate data
    Joe,
    I was looking for the following results:
    0.0
    0.1
    0.0
    r/Curtis
    joe wilcox <falon5000 (AT) yahoo (DOT) comwrote:
    Using your sample code, I wrote this simple test:
    procedure TfrmMain.Button1Cli ck(Sender: T);
    var
    Data : string;
    begin
    Data := '0.0000.1370. 000';
    memo.lines.add( Copy (Data, 1, 3));
    memo.lines.add( Copy (Data, 6, 8));
    memo.lines.add( Copy (Data, 11, 13));
    end;
    Here's the result I got -
    0.0
    0.1370.
    0. 000
    That's pretty much what you're looking for, isn't it?
    Joe Wilcox
    "Reading Cliff Notes to know a novel is like eating Count Chocula to know steak"
    "Nine women cannot have a baby in one month"
    falon5000 (AT) yahoo (DOT) com
    Message
    From: Curtis cloud <curtiscld (AT) yahoo (DOT) com>
    To: delphi-en@yahoogrou ps.com
    Sent: Thursday, January 4, 2007 3:13:44 PM
    Subject: [delphi-en] Using the copy function to separate data
    ALL,
    I have a telnet connection to a server computer that constant broadcast data to me each second. The data that I receive has spaces and tabs in the middle of the string. I receive the data I remove all spaces and tabs to get a single stream of data. After I receive the stream I attempt to parse the data into segments using the copy function.
    My problem is this when I look at the stream the data looks fine but when I use the copy funtion it does not work properly on the data.
    Here is an example :
    Single stream from a telnet connection
    0.0000.1370. 000
    Data := ' 0.0000.1370. 000'
    Copy (Data, 1, 3) yield value 0.0 which is fine.
    Copy (Data, 6, 8) yields value 0.0000.0 which is wrong.
    Copy (Data, 11, 13) yields value 0.0000.0000. 0 which is wrong.
    I'm not sure why I am not receiving the correct data.
    r/Curtis
    __
    Do You Yahoo!?
    Tired of spam? Yahoo! Mail has the best spam protection around
    http://mail. yahoo.com
    [Non-text portions of this message have been removed]
    [Non-text portions of this message have been removed]
    __
    Do You Yahoo!?
    Tired of spam? Yahoo! Mail has the best spam protection around
    http://mail. yahoo.com
    [Non-text portions of this message have been removed]
    [Non-text portions of this message have been removed]

Re: Using the copy function to separate data


max 4000 letters.
Your nickname that display:
In order to stop the spam: 8 + 8 =
QUESTION ON "Delphi"

EMSDN.COM