在Java中使用startsWith和endsWith时如何忽略大小写?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了在Java中使用startsWith和endsWith时如何忽略大小写?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1634字,纯文字阅读大概需要3分钟。
内容图文
![在Java中使用startsWith和endsWith时如何忽略大小写?](/upload/InfoBanner/zyjiaocheng/699/82f47298845a4372853d2020c1190dc6.jpg)
参见英文答案 > startsWith() method of string ignoring case 7个
这是我的代码:
public static void rightSel(Scanner scanner,char t)
{
/*if (!stopping)*/System.out.print(": ");
if (scanner.hasNextLine())
{
String orInput = scanner.nextLine;
if (orInput.equalsIgnoreCase("help")
{
System.out.println("The following commands are available:");
System.out.println(" 'help' : displays this menu");
System.out.println(" 'stop' : stops the program");
System.out.println(" 'topleft' : makes right triangle alligned left and to the top");
System.out.println(" 'topright' : makes right triangle alligned right and to the top");
System.out.println(" 'botright' : makes right triangle alligned right and to the bottom");
System.out.println(" 'botleft' : makes right triangle alligned left and to the bottom");
System.out.println("To continue, enter one of the above commands.");
}//help menu
else if (orInput.equalsIgnoreCase("stop")
{
System.out.println("Stopping the program...");
stopping = true;
}//stop command
else
{
String rawInput = orInput;
String cutInput = rawInput.trim();
if (
我想让用户了解如何输入命令,例如:右上角,右上角,右上角,左上角等.
为此,我正在尝试,在最后一次if(,检查cutInput是以“top”还是“up”开头并检查cutInput是以“left”还是“right”结束,所有这些都是不区分大小写的. 这是可能吗?
这样做的最终目的是允许用户在一行输入中从三角形的四个方向中选择一个.这是我能想到的最好的方式,但是对于一般的编程我来说还是很新的,可能会使事情变得复杂.如果我是,并且它转变为更简单的方式,请告诉我.
解决方法:
像这样:
aString.toUpperCase().startsWith("SOMETHING");
aString.toUpperCase().endsWith("SOMETHING");
内容总结
以上是互联网集市为您收集整理的在Java中使用startsWith和endsWith时如何忽略大小写?全部内容,希望文章能够帮你解决在Java中使用startsWith和endsWith时如何忽略大小写?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。