长度为

时间:2018-01-22 13:23:16

标签: java regex algorithm

What does this definition of contiguous subsequences mean?

我正在解决问题,但我不了解连续的子序列是如何工作的。例如,

Finding all 3 character length substrings in a string

public class Subsequences {

    public static void main(String[] args) {

        String s = "CCAATA CCGT";
        String ss = s.replaceAll("\\s+","");

        int n = 4; // subsequences of length

        for (int i=0; i <= ss.length() - n; i++) {
             String substr = ss.substring(i, i + n);
             if (substr.matches("[a-zA-Z]+")) { 
                 System.out.println(substr); 
                }
        }
    }
}

输出:

  

CCAA   CAAT   AATA   ATAC   TACC   ACCG   CCGT

有人会向我解释这个循环是做什么的吗?

for (int i=0; i <= ss.length() - n; i++) {
                 String substr = ss.substring(i, i + n);
                 if (substr.matches("[a-zA-Z]+")) { 
                     System.out.println(substr); 
                    }
            }

1 个答案:

答案 0 :(得分:0)

确保子字符串仅包含字母(无空格)