java中如何查找字符串中的EOF?
我正在从事学校项目。他们告诉我,我将得到一个字符串,其中包含一个实际的程序,例如......
导入java.io.*\n公共类A{\n...........EOF
我的工作是在该字符串(程序)中查找特定的正则表达式。
现在我的问题是..
void myFunc(String s)
{
while(s.charAt(i) != EOF) /*needed replacement for EOF*/
{
// Actual Code
}
}
在上面的代码中,如何查找字符串中是否达到 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
BufferedReader rd=new BufferedReader(new InputStreamReader(new FileInputStream("Input.txt"),"UTF-8"));
BufferedReader rd=new BufferedReader(new InputStreamReader(new FileInputStream("Input.txt"),"UTF-8"));
您不太可能需要这个 - 您可能只需要读取到字符串末尾,并且由于它是文件内容的表示,因此您的老师将其称为 EOF。
然而……
有一个字符叫EOF。它也称为 control-Z,因为这就是您键入它的方式。如果你想将它包含在字符串中,你必须将其输入为“\u001a”,如下所示:
如果你真的需要这个,你的老师可能比我年长,而且我可能年纪大到可以成为你的祖父;- )
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:
If you really need this, your teacher is probably older than me, and I'm probably old enough to be your grandfather ;-)
字符串中没有 EOF 字符。您只需要 迭代字符串中的字符:
There is no EOF character in a string. You just need to iterate over the characters in the string: