简体   繁体   English

检查特定行中的给定字符串

[英]check a given string in specific line

I have a very dump question.I am reading a file line by line which is ".html" file.I want to check a perticular contains exits in line or not. 我有一个非常倾销的问题。我正在逐行读取一个文件,这是“.html”文件。我想检查一个包含退出的特定的。 For this I am using String class contains method. 为此我使用String类包含方法。

I am checking the follwing content in line which contain inverted comma. 我正在检查包含倒置逗号的行中的内容。

<div class="tupBin"/>

My syntax is like this.. 我的语法是这样的..

Str line;
line.contains()

What should I write in contains braces..? 我应该写什么包含大括号..?

Thanks in advance for help. 在此先感谢您的帮助。

Edit: If you want to do a search over a string which contains quotes/inverted commas in it already, you just need to take special care with your input. 编辑:如果您想搜索已经包含引号/引号的字符串,您只需要特别注意您的输入。 You can "escape" special characters to tell Java to treat them as normal characters. 您可以“转义”特殊字符,告诉Java将它们视为普通字符。 You do this by putting a backslash before them. 你可以通过在它们前加一个反斜杠来做到这一点。 In fact, more than just the quotes will be a problem - so will the < and > Check this link out for more information about escaping characters. 事实上,不仅仅是引号将是一个问题 - <和>将检查此链接以获取有关转义字符的更多信息。 So to search for your string, you would write: 所以要搜索你的字符串,你会写:

boolean didContain = line.contains("\<div class=\"tupBin\"/\>");

If the input is read in by a scanner or stream, most likely it will be escaped for you already. 如果输入是由扫描仪或流读入的,则很可能它已经为您转义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM