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?
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.
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.
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 ;-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With