检查给定字符串中是否存在回车 [英] check carriage return is there in a given string

查看:72
本文介绍了检查给定字符串中是否存在回车的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我,我正在从文件中读取一些行,我正在检查每一行是否具有 CRLF 的 windows 类型.如果任何行中不存在 '\n' 或 '\r',则必须报告错误.我尝试使用以下代码,即使该行没有\r",也不会报告任何错误

i,m reading some lines from a file and i'm checking whether each line has windows type of CRLF or not. If either '\n' or '\r' is absent in any line, it has to report an error. I tried with the below code, even if the line doesnt have '\r', it is not reporting any error

Open_file = open(File_Name,'r').readlines()
while Loop_Counter!= Last_Line:
        Line_Read = Open_file[Loop_Counter]
        if('\r\n' in Line_Read):
            pass
        else:
            print Loop_Counter

谢谢

推荐答案

试试这个

Open_file = open(File_Name,'rb').readlines()

你必须以二进制模式打开文件

you have to open file in binary mode

这篇关于检查给定字符串中是否存在回车的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆