[英]How do I extract words from a string?
我做了一些研究,但只能找到搜索结果的答案。 我试图从一个字符串中提取一个单词,并从另一个字符串中添加一个单词,以替换被删除的单词。 每种情况都是不同的,所以我不能使其恒定。 我非常感谢您的帮助!
package rudolph;
import javax.swing.JOptionPane;
public class IfBlankWasBlank {
public static void main(String[] args) {
String charInput = "";
String thing = "";
String pun = "";
charInput = JOptionPane.showInputDialog(null,
"Enter the person or thing you'd like to make fun of:");
thing = JOptionPane.showInputDialog(null,
"Enter the thing that " + charInput +" is doing:");
pun = JOptionPane.showInputDialog(null,
"Enter the pun that " + charInput + " is doing:");
String msg = "If " + charInput + " was " + thing + ", then they'd be " + pun + ".";
JOptionPane.showMessageDialog(null, msg);
}
}
所以,如果我在鲁道夫进入红鼻子驯鹿在CharInput
字符串,高效节能的thing
串,并在LED pun
字符串,我想msg
是“如果鲁道夫红鼻子驯鹿是节能,那么他们会成为LED鼻子驯鹿鲁道夫。” 我知道这很傻,但是我想知道如何利用它! 非常感谢你的帮助!
您应该使用字符串拆分方法。 String#split()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.