How to remove line feed from ascii string

I have a program where an ascii string is received from the serial port and put into an sbuf (serial buffer) . When I display the string in a TListBox the line feed shows up as a small black vertical line. I have include a code snippet where I receive the string into the serial buffer. I was wondering if anyone can tell me a good way to remove the line feed before going to the TListBox. Also note that the string does not have a carriage return just a line feed. Thank you in advance!
Craig

procedure TForm1.rxProc(const buf; len: word);
var
bx: byte;
idx: integer;
begin
for idx := 0 to len - 1 Do Begin
bx := TByteArray(buf) [idx]; // Get next byte
sbuf := sbuf + CHR(bx); //Append byte to string
if (bx = 10) then begin // Byte is LF
SendData (sbuf); //Send serial buffer to map server
lb.Items.Insert(0, sbuf); //Insert sbuf at top of listbox
sbuf :=''; // Clear sbuf
end;
end;
end;

Comments

  • : I have a program where an ascii string is received from the serial
    : port and put into an sbuf (serial buffer) . When I display the
    : string in a TListBox the line feed shows up as a small black
    : vertical line. I have include a code snippet where I receive the
    : string into the serial buffer. I was wondering if anyone can tell me
    : a good way to remove the line feed before going to the TListBox.
    : Also note that the string does not have a carriage return just a
    : line feed. Thank you in advance!
    : Craig
    :
    : procedure TForm1.rxProc(const buf; len: word);
    : var
    : bx: byte;
    : idx: integer;
    : begin
    : for idx := 0 to len - 1 Do Begin
    : bx := TByteArray(buf) [idx]; // Get next byte
    : sbuf := sbuf + CHR(bx); //Append byte to string
    : if (bx = 10) then begin // Byte is LF
    : SendData (sbuf); //Send serial buffer to map server
    : lb.Items.Insert(0, sbuf); //Insert sbuf at top of listbox
    : sbuf :=''; // Clear sbuf
    : end;
    : end;
    : end;
    The easiest is to use the Replace() function. This allows your to replace any substring (or single character) with something else (or nothing). See help files for more info on the Replace() function.
  • : : I have a program where an ascii string is received from the serial
    : : port and put into an sbuf (serial buffer) . When I display the
    : : string in a TListBox the line feed shows up as a small black
    : : vertical line. I have include a code snippet where I receive the
    : : string into the serial buffer. I was wondering if anyone can tell me
    : : a good way to remove the line feed before going to the TListBox.
    : : Also note that the string does not have a carriage return just a
    : : line feed. Thank you in advance!
    : : Craig
    : :
    : : procedure TForm1.rxProc(const buf; len: word);
    : : var
    : : bx: byte;
    : : idx: integer;
    : : begin
    : : for idx := 0 to len - 1 Do Begin
    : : bx := TByteArray(buf) [idx]; // Get next byte
    : : sbuf := sbuf + CHR(bx); //Append byte to string
    : : if (bx = 10) then begin // Byte is LF
    : : SendData (sbuf); //Send serial buffer to map server
    : : lb.Items.Insert(0, sbuf); //Insert sbuf at top of listbox
    : : sbuf :=''; // Clear sbuf
    : : end;
    : : end;
    : : end;
    : The easiest is to use the Replace() function. This allows your to
    : replace any substring (or single character) with something else (or
    : nothing). See help files for more info on the Replace() function.

    Thank you very much for the tip, I will give that try.

  • : : I have a program where an ascii string is received from the serial
    : : port and put into an sbuf (serial buffer) . When I display the
    : : string in a TListBox the line feed shows up as a small black
    : : vertical line. I have include a code snippet where I receive the
    : : string into the serial buffer. I was wondering if anyone can tell me
    : : a good way to remove the line feed before going to the TListBox.
    : : Also note that the string does not have a carriage return just a
    : : line feed. Thank you in advance!
    : : Craig
    : :
    : : procedure TForm1.rxProc(const buf; len: word);
    : : var
    : : bx: byte;
    : : idx: integer;
    : : begin
    : : for idx := 0 to len - 1 Do Begin
    : : bx := TByteArray(buf) [idx]; // Get next byte
    : : sbuf := sbuf + CHR(bx); //Append byte to string
    : : if (bx = 10) then begin // Byte is LF
    : : SendData (sbuf); //Send serial buffer to map server
    : : lb.Items.Insert(0, sbuf); //Insert sbuf at top of listbox
    : : sbuf :=''; // Clear sbuf
    : : end;
    : : end;
    : : end;
    : The easiest is to use the Replace() function. This allows your to
    : replace any substring (or single character) with something else (or
    : nothing). See help files for more info on the Replace() function.

    The Replace() function is incorrect--it's actually StringReplace(). And this will also not remove the control characters. If the control characters are at the beginning or the end of the string, then use Trim().
    I had a PHP echo function returning #$A'mystring' and that's where Trim() did the job
  • : : : I have a program where an ascii string is received from the serial
    : : : port and put into an sbuf (serial buffer) . When I display the
    : : : string in a TListBox the line feed shows up as a small black
    : : : vertical line. I have include a code snippet where I receive the
    : : : string into the serial buffer. I was wondering if anyone can tell me
    : : : a good way to remove the line feed before going to the TListBox.
    : : : Also note that the string does not have a carriage return just a
    : : : line feed. Thank you in advance!
    : : : Craig
    : : :
    : : : procedure TForm1.rxProc(const buf; len: word);
    : : : var
    : : : bx: byte;
    : : : idx: integer;
    : : : begin
    : : : for idx := 0 to len - 1 Do Begin
    : : : bx := TByteArray(buf) [idx]; // Get next byte
    : : : sbuf := sbuf + CHR(bx); //Append byte to string
    : : : if (bx = 10) then begin // Byte is LF
    : : : SendData (sbuf); //Send serial buffer to map server
    : : : lb.Items.Insert(0, sbuf); //Insert sbuf at top of listbox
    : : : sbuf :=''; // Clear sbuf
    : : : end;
    : : : end;
    : : : end;
    : : The easiest is to use the Replace() function. This allows your to
    : : replace any substring (or single character) with something else (or
    : : nothing). See help files for more info on the Replace() function.
    :
    : The Replace() function is incorrect--it's actually StringReplace().
    : And this will also not remove the control characters. If the control
    : characters are at the beginning or the end of the string, then use
    : Trim().
    : I had a PHP echo function returning #$A'mystring' and that's where
    : Trim() did the job
    :
    You're parely correct: the function is called StringReplace(). But it can replace any sequence of characters with any other sequence of characters. Thus
    [code]
    StringReplace(SomeText, #13#10, '', [rfReplaceAll]);
    [/code]
    replaces all the line breaks.
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