How to REMOVE weird CHARACTER on LCD

Can somebody tell me how to remove this weird character at the end of text? The text came from a .txt file on my sdcard.

You would remove the "weird" character by not printing any non-printable characters to the LCD. Carriage returns and line feeds are common in files, but have no place on an LCD.

PaulS:
You would remove the "weird" character by not printing any non-printable characters to the LCD. Carriage returns and line feeds are common in files, but have no place on an LCD.

I dont know how to remove carriage return and line feed..

In my text file its just "5code1hr"

Post your code please. Use the code tags, to find out how to do that, read the how to use this forum.

projectdimpreza:
I dont know how to remove carriage return and line feed..

First, you find out what their ASCII values are, then you modify the code you didn't post so that it doesn't send those ASCII codes to the LCD

Bringamosa:
Post your code please. Use the code tags, to find out how to do that, read the how to use this forum.

This is where LCD gets the text to be printed.

void get_code() {
    char line[25];
    int n;
    SdFile rdfile("1hr.txt", O_READ);
    if (!rdfile.isOpen()) {
        error("Error getting code!");
    }
    Serial.println(F("Done!"));
    while ((n = rdfile.fgets(line, sizeof(line))) > 0) {
        if (line[n - 1] == '\n') {
            codeCounter++;
            if (codeCounter == codeRead) {
                code = line;
            }
        } 
    }

    if (code != "")
    {
    codeCounter = 0;
    Serial.print("CODE: ");
    Serial.println(code);
    lcd.Setcursor(0,7);
    lcd.print(code);
    }
    rdfile.close();
}

if (line[n - 1] == '\n') { There, you already have a test for newline.

AWOL:
if (line[n - 1] == '\n') { There, you already have a test for newline.

So how do i prevent it from printing the newline on the lcd?

The notepade text looks like this.

1code1hr
2code1hr
3code1hr
and so on...

Its selecting one line at a time to be displayed on the screen every button press.. thats why i have the codes separated every line..

    lcd.print(code);

If only we knew what type of variable code is...

I'm going to guess String, which has some useful methods YOU could research. Something to trim() white space characters would be useful, if the class had such a method...

projectdimpreza:
So how do i prevent it from printing the newline on the lcd?

Don't send it.
But actually doesn't really print on the screen. The LCD prints a custom character which, unless you have programmed that position, will be garbage like you are seeing.

You must either write the code to remove any or characters from the string before you send it to the LCD, or use a different file reading call that eliminates them for you.

The notepade text looks like this.

1code1hr
2code1hr
3code1hr
and so on...

That doesn't really show what is in the actual file.
To see what is really in the file you must look at the actual bytes in the file (the hex values of each byte).
Of particular importance is what character(s) is used to delineate lines?

To complicate things, both Apple and Microsoft decided to not follow the lead set by Unix decades earlier on how to delineate lines in a text file. Both did it differently.
So for something like a text file, which sounds simple, it isn't so simple when having to deal with line delineations/endings.

The problem now is that many of the development tools and how they work came from Unix but companies like Apple and Microsoft have sometimes deviated away doing things the way Unix did.
So you can have issues like you are seeing when trying to process lines in "text" file.

The 3 ways that text files can use to mark line endings:
Unix used a single
Apple used a in the early days (I think they now use or )
Microsoft / CPM uses (I think Microsoft very recently added support for using only as an option at least in their editors like notepad)

So that means a "text" file could have either of these 3 line endings.

Why this matters is that if you using something like a fgets() function it typically reads a line from the input stream and puts the line of text (including the line delineation characters) into the buffer string.

So you can have a line buffer string that has one of 3 potential line endings in it.
If you don't want the line ending characters, (which you don't when sending to the LCD) you must write the code to remove it, taking into consideration that it could be any of the 3 types.

Alternatively, you could potentially use a different line reading/processing routine (if one is available like gets() ) that eliminates them for you.

--- bill

Thanks for the reply.. i fixed the problem by adding trim();

That sketch looks really complicated to me, and I haven't had a decent look at it, but doesn't reading an SD card work like reading from Serial? (I may be wrong there, of course.)

So since you are reading in a character at a time, just look for a \n or \r. Only lcd.print() those characters which aren't \n or \r.

Something like:

if (incomingChar != '\n' && incomingChar != '\r') lcd.print(incomingChar);

Then when you do encounter a \n, if you were doing a Serial.print() that would be invisibly handled and the next character would be on the next line of the monitor, but with an lcd you would re-position the cursor back at your origin:

if (incomingChar == '\n') lcd.setCursor(0,0);

... ready for the next character, which is the first character in the next record.