removing characters from a string variable - Programmers Heaven

Howdy, Stranger!

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

Categories

removing characters from a string variable

delljohnbdelljohnb Posts: 81Member
I'm wanting to peel the last several characters off a string variable, and I'm looking for a good routine/function what will perform this. Here is the situation....

read a line from a file into a string variable.

the length of the string is variable, and it has several commas on the end of the "usable" data. While the number of commas is variable, at the time that I read the line, the number of commas in the line is known. Does anyone know of a good routine to accomplish this?

Thanks in advance;
Delljohnb

Comments

  • zibadianzibadian Posts: 6,349Member
    : I'm wanting to peel the last several characters off a string variable, and I'm looking for a good routine/function what will perform this. Here is the situation....
    :
    : read a line from a file into a string variable.
    :
    : the length of the string is variable, and it has several commas on the end of the "usable" data. While the number of commas is variable, at the time that I read the line, the number of commas in the line is known. Does anyone know of a good routine to accomplish this?
    :
    : Thanks in advance;
    : Delljohnb
    :
    You can use the Delete() function for this. Here is a small code, which will remove all commas from the end.
    [code]
    while s[Length(s)]=',' do
    Delete(s, Length(s), 1);
    [/code]
    This code also works if the number of commas is unknown.
  • delljohnbdelljohnb Posts: 81Member
    : : I'm wanting to peel the last several characters off a string variable, and I'm looking for a good routine/function what will perform this. Here is the situation....
    : :
    : : read a line from a file into a string variable.
    : :
    : : the length of the string is variable, and it has several commas on the end of the "usable" data. While the number of commas is variable, at the time that I read the line, the number of commas in the line is known. Does anyone know of a good routine to accomplish this?
    : :
    : : Thanks in advance;
    : : Delljohnb
    : :
    : You can use the Delete() function for this. Here is a small code, which will remove all commas from the end.
    : [code]
    : while s[Length(s)]=',' do
    : Delete(s, Length(s), 1);
    : [/code]
    : This code also works if the number of commas is unknown.
    :
    EXCELLENT!!! Wow...fast response. That works great!!! I knew there was a short routine out there. I just couldn't put together the logic manipulation to get a concise one....this will work GREAT!. Thanks.

    Delljohnb

Sign In or Register to comment.