java - 字符串的额外 java 输入验证
问题描述
我想这样做以便仍然可以检测到短输入,例如“Londo”和“Lon”,但希望保持较小并使用它而无需基本上复制和粘贴代码,有什么提示吗?谢谢你。
if (Menu.answer1.equals("London"))
{
if (location.equals("London")) {
System.out.print(location + " ");
System.out.print(date + " ");
System.out.print(degrees + "C ");
System.out.print(wind + "MPH ");
System.out.print(winddirection + " ");
System.out.print(weather + " ");
System.out.println("");
}
解决方案
您可以使用startsWith()
String city = "London";
if (city.startsWith("Lon")) {
// do something
}
推荐阅读
- android - 无法在 android studio 3.4.1 中解析符号“NotificationCompat”
- php - 移动和替换文件
- deep-learning - 如何使用pytorch仅使用vgg16的最后几层
- java - 无法使用 Web 内容文件夹中图像的 getClass.getResource 创建 URL
- javascript - 多个事件以创建动态 +/- 可编辑输入
- javascript - GatsbyJS Invariant Violation:在尝试推断 GraphQL 类型时遇到错误
- python-3.x - 如何使用 Spacy 禁用括号上的拆分句子?
- html - 如何更改材质 ui 中小屏幕的布局?
- python - python中的Lstrip函数
- pandas - 使用 Dataflow 的 Pandas read_gbq 初始化错误