duanquyong8164 2018-09-12 08:05
浏览 495
已采纳

如果没有换行符,如何从reader.ReadString获取最后一行

I've been writing this Php parser in Go, but I seem to have hit a little problem, which is that sometimes the final line is not added to the new file I am writing.

Basically I go over the original Php file, do some obfuscating, and then write those obfuscated lines to a new file.

Problem is that at times I run into a file that does not have a newline at the end, and I assume that line, err := reader.ReadString(' ') will not read a string if it does not have the delimiting character at the end?

Is there an easy solution for this that doesn't involve using Scanner, because a lot of the parsing code is dependent on interpreting newlines...

  • 写回答

1条回答 默认 最新

  • du27271 2018-09-12 08:24
    关注

    Problem solved, I was breaking out of the loop before adding the last character to my obfuscated line. Moving the EOF handling to the bottom resolved it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 一道python难题2
  • ¥15 一道python难题
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备