我还在研究Java项目,想问一下是否有人可以帮助我?
我问我是否可以用"startsWith"检查带有多个字母的字符串?
喜欢:
if (string Alpha.startsWith("a"||"A"||"b"||"B"||"c"||"C"||"d"||"D")){
System.out.println("Wrong!");
System.out.println("\n");
}
else{
System.out.println("Wrong Key!");
Run Code Online (Sandbox Code Playgroud)
有解决方案吗
有什么我可以用来看看一个数字是否与另一个数字相同?防爆.5643和5377都以5开头.
有没有办法用数字做这个或者它们必须是字符串?(以..开始?)
所以我有一个问题.今天我开始优化我的代码,并以此为例:
return !this.message.startsWith("/");
Run Code Online (Sandbox Code Playgroud)
那么我从这里采取我的优化技巧(链接到规则)
那么应该如何将代码写入更优化的版本?我目前得到:
return !(this.message.length () > ZERO) && this.message.charAt(ZERO) == Slash;
Run Code Online (Sandbox Code Playgroud)
我写得对吗?如果我写错了,那么我写错了什么?
谢谢,tambre
Java String.startsWith()中的快速问题需要某种通配符.
我需要检查,看是否有链接开头http://或本地驱动器(c:\,d:\等),但我不知道的驱动器号.
所以我想我需要类似的东西 myString.startsWith("?:\\")
有任何想法吗?
为此欢呼,但我想我需要在此基础上继续努力.
我现在需要迎合
1.http://
2.ftp://
3.file:///
4.c:\
5.\\
Run Code Online (Sandbox Code Playgroud)
这太过分了,但我们想确保我们抓住了所有这些.
我有
if(!link.toLowerCase().matches("^[a-z]+:[\\/]+.*")) {
Run Code Online (Sandbox Code Playgroud)
适用于任何字符或字符后跟一个:( 示例http:,ftp:,C :),其中包括1-4但我无法满足\\
我能得到的最近的就是这个(它有效,但在regEx中得到它会很好).
if(!link.toLowerCase().startsWith("\\") && !link.toLowerCase().matches("^[a-z]+:[\\/]+.*")) {
Run Code Online (Sandbox Code Playgroud) 我有一个字符串数组,我只需要那些以"81"或"82"开头的条目.我试过这样的:
var lines = File.ReadAllLines(fileName); // This returns an array of strings
lines = lines.TakeWhile(item => item.StartsWith("81") ||item.StartsWith("82")).ToArray();
Run Code Online (Sandbox Code Playgroud)
但这只是行不通.它返回一个空字符串数组.
当我使用for循环遍历行并每次进行比较时
if (!firstline.Substring(0, 2).StartsWith("81")) continue;
Run Code Online (Sandbox Code Playgroud)
然后我拿了所需的条目,它工作得很好.
有任何建议如何使用LINQ正确吗?
我正在尝试编写一个简单的逻辑,它将在一个列表中查找以其他列表中的单词开头的单词.例如:
a = ["let","test","g"]
b = ["letter", "testing","good","egg","protest"]
Run Code Online (Sandbox Code Playgroud)
应该回来:letter, testing, good.
我已经涉足.startswith()但似乎无法使用整个列表进行搜索.还试过:
if any(i in a for i in b):
Run Code Online (Sandbox Code Playgroud)
但是我无法得到任何结果.
我是python的新手,我必须创建一个验证DNA序列的程序.(DNA序列的背景非常快)为了有效:•字符数可以被3整除•前3个字符是ATG•最后3个字符是TAA,TAG或TGA.
我的问题是在if语句中使用布尔项.
endswith=(DNA.endswith("TAA"))
endswith2=(DNA.endswith("TAG"))
endswith3=(DNA.endswith("TGA"))
if length%3==0 and startswith==true and endswith==true or endswith2==true or endswith3==true:
return ("true")
Run Code Online (Sandbox Code Playgroud)
此代码返回以下错误:未定义全局名称"true"
我如何解决这个问题,而且在最后一个笔记中我真的很抱歉.这个问题的答案可能非常简单,在你的脑海中,一个2岁的孩子可以编码:/我做过研究,但我根本没有运气.所以我感谢你花时间去读我的愚蠢问题.
我正在使用codingBat练习练习递归以获得自己的娱乐.我正在做这个练习:
给定一个字符串,递归计算字符串中出现小写"hi"的次数,但是不计算在它们之前立即有"x"的"hi".
countHi2("ahixhi") ? 1
countHi2("ahibhi") ? 2
countHi2("xhixhi") ? 0
Run Code Online (Sandbox Code Playgroud)
我试图做这个代码,但它不断抛出超出范围的异常:
public int countHi2(String str){
if(str.length()<2){
return 0;
}
else if(str.substring(0,3).equals("xhi")){
return countHi2(str.substring(3));
}
else if(str.substring(0,2).equals("hi")){
return 1+countHi2(str.substring(2));
}
else{
return countHi2(str.substring(1));
}
}
Run Code Online (Sandbox Code Playgroud)
我更改了substring()并等于startsWith()
else if(str.startsWith("xhi")){
return countHi2(str.substring(3));
Run Code Online (Sandbox Code Playgroud)
现在效果很好,有人可以指出为什么我的第一个代码不正确吗?startsWith()和equals()之间有区别吗?
我想在数组列表中运行for循环并打印出任何带有"monkey"字样的内容.我在下面编写了以下代码,但它给了我一个错误.我不太确定我做错了什么.任何帮助都会很棒,谢谢.
a= "monkeybanana"
b= "monkeyape"
c= "apple"
list= [a, b, c]
print "The words that start with monkey are:"
for k in words:
if list.startswith('monkey'):
print list
Run Code Online (Sandbox Code Playgroud) 我想在字符串中查找文本(使用C#),以单词"Column"开头并结束任何数字(例如"100").
总之,我想找到:
Column1
Column100
Column1000
但是没有找到:
Column_1
_Column1
Column1 $
我找不到使用正则表达式的方法.
startswith ×10
java ×5
if-statement ×3
python ×3
string ×3
c# ×2
ends-with ×2
python-2.7 ×2
equals ×1
for-loop ×1
linq ×1
list ×1
optimization ×1
python-3.x ×1
recursion ×1
regex ×1
sub-array ×1