简体   繁体   English

一次移动两个字母(子字符串)Java

[英]Moving two letters at once (Sub Strings) Java

So I have my whole program working, it even moves on letter if it isn't a vowel, however it's suppose to move the two constant if they are right next to each other.所以我的整个程序都在工作,如果它不是元音,它甚至会在字母上移动,但是如果它们彼此相邻,它应该移动两个常量。 So I have messed around with the substrings and making the char at (0) a variable, but still haven't got any luck any ideas?所以我弄乱了子字符串并使 (0) 处的字符成为变量,但仍然没有任何想法?

So it would be the if (true) part.所以这将是 if (true) 部分。

Here is my code:这是我的代码:

You can use regex match look for the vowels and return the first occurrence.您可以使用正则表达式匹配查找元音并返回第一次出现。 The code snippet below will look for the first vowel in the word and return the its index.下面的代码片段将查找单词中的第一个元音并返回其索引。 Then you can use that in your substring instead of just taking the first letter.然后你可以在你的子字符串中使用它,而不仅仅是取第一个字母。

String word = "test";
Pattern pattern = Pattern.compile("[aeiou]");
Matcher matcher = pattern.matcher(word); 
if(matcher.find()){
  System.out.println(matcher.start());
}

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

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