Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find EOF in a string in java?

Tags:

java

string

eof

I am working in school project. In that what they told is, I will be given a String which contains an actual program like....

import java.io.*\npublic class A{\n...........EOF

And My job is to find particular regular expressions in that String(Program).

Now My question is..

void myFunc(String s)
{
 while(s.charAt(i) != EOF) /*needed replacement for EOF*/
 {
 // Actual Code
 }
}

In the above code, how to find whether EOF is reached in a string?

like image 976
Muthu Ganapathy Nathan Avatar asked Sep 28 '11 23:09

Muthu Ganapathy Nathan


People also ask

How do I find my EOF character?

The EOF in C/Linux is control^d on your keyboard; that is, you hold down the control key and hit d. The ascii value for EOF (CTRL-D) is 0x05 as shown in this ascii table . Typically a text file will have text and a bunch of whitespaces (e.g., blanks, tabs, spaces, newline characters) and terminate with an EOF.

What value is EOF in Java?

There isn't such a thing in standard Java AFAIK. EOF is more of a concept than a character. Most Java file functions return null when they hit EOF, so maybe you could use that. Things at that level (end-of-line, end-of-file) are OS-specific, not language-specific.


1 Answers

It's unlikely that you need this - you probably just need to read till the end of the string, and since it's a representation of a file's contents, your teacher referred to it as EOF.

However...

There is a character called EOF. It's also called control-Z, because that's how you type it. If you want to include it in a string, you have to type it as "\u001a" as in:

String iHaveAnEof = "file ends here\u001a";

If you really need this, your teacher is probably older than me, and I'm probably old enough to be your grandfather ;-)

like image 67
Ed Staub Avatar answered Oct 02 '22 05:10

Ed Staub