简体   繁体   English

如何使用CharSequence

[英]How to use CharSequence

Hey i'm having some trouble understanding CharSequence. 嘿,我在理解CharSequence时遇到了一些麻烦。
I think this will be the perfect method to help with my hw but im having trouble understanding how to use it. 我认为这将是帮助我的硬件的理想方法,但是我在理解如何使用它方面遇到了麻烦。
How do i make the sequence < /p> comes up. 我如何使序列</ p>出现。

This is what i have so far: 这是我到目前为止所拥有的:

String s = "</p>";
char c;

while(reads.hasNext()){
c = reads.next();
    s = "" + c;
    if (inputPath.contains(?)) {
    // how do i make it return true if it contains < /p>
    }
}

Assuming you are talking about java.lang.CharSequence , it is an interface, and is the parent for String, StringBuilder, and StringBuffer (and some other things). 假设您在谈论java.lang.CharSequence ,它是一个接口,并且是String,StringBuilder和StringBuffer(以及其他一些东西)的父级。

It looks like you are more looking to see if the input you have so fat has, or contains a given string (</p> ). 看起来您似乎更想看看您输入的内容是否足够或包含给定的字符串(</p> )。 To do that you could make use of the Pattern class or the String.equals or String.indexOf method (or the StringBuilder version). 为此,您可以使用Pattern类或String.equals或String.indexOf方法(或StringBuilder版本)。

You can test that one String contains another using indexOf() : 您可以使用indexOf()测试一个String包含另一个String:

if (inputPath.indexOf("< /p>") != -1) {
    // inputPath contains "< /p>" somewhere in it
}

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

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