在字节数组中查找单行注释 [英] Find single line comments in byte array
本文介绍了在字节数组中查找单行注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有可能在从文件读取到字节数组的行中找到 //
的实例,然后从 //中截取
到行尾吗?我正在尝试
Is it possible to find instances of //
in a line read from a file into a byte array and then "snip" from //
to the end of the line out? I'm trying
FileInputStream fis = new FileInputStream(file);
byte[] buffer = new byte[8 * 1024];
int read;
while ((read = fis.read(buffer)) != -1)
{
for (int i = 0; i < read; i++)
{
if (buffer[i] == '//')
{
buffer = buffer[0:i];
}
}
}
但我得到
部分。我是在做错什么,还是这是不可能的?处的字符常量常量
如果上的(buffer [i] =='//')
'//'
but I'm getting Invalid character constant
at if (buffer[i] == '//')
on the '//'
part. Am I doing something wrong, or is this just not possible?
推荐答案
老式解决方案
for (int i = 0; i < read-1; i++)
{
(if (buffer[i] == '/') && (buffer[i+1]== '/'))
{
buffer = buffer[0:i];
}
}
这篇关于在字节数组中查找单行注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文