如何检查字符串是否以JavaScript中的特定字符结尾?
示例:我有一个字符串
var str = "mystring#";
Run Code Online (Sandbox Code Playgroud)
我想知道该字符串是否以#
.结尾.我怎么检查呢?
endsWith()
JavaScript中有方法吗?
我有一个解决方案是获取字符串的长度并获取最后一个字符并检查它.
这是最好的方式还是有其他方式?
正在寻找名称以某些子字符串开头的预测变量,找不到任何类似的函数.
我试图找到一个动态ID名称始终以"register"结尾的输入元素.到目前为止我试过这个
"//input[@id[ends-with(.,'register')]]"
Run Code Online (Sandbox Code Playgroud)
还有这个
"//input[ends-with(@id,'register')]"
Run Code Online (Sandbox Code Playgroud)
这些都不会导致元素.我究竟做错了什么?同时这工作:
"//input[@id[contains(.,'register')]]"
Run Code Online (Sandbox Code Playgroud)
这是源的一部分:
<td class="input">
<input id="m.f0.menu.f2.volumeTabs.BLOCK_COMMON.tcw.form.register" name="m.f0.menu.f2.volumeTabs.BLOCK_COMMON.tcw.form.register" class="aranea-checkbox" type="checkbox"> </td>
Run Code Online (Sandbox Code Playgroud) 这是我的代码:
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 …
Run Code Online (Sandbox Code Playgroud) 我有一个字符串:
myStr = "Chicago Blackhawks vs. New York Rangers"
Run Code Online (Sandbox Code Playgroud)
我也有一个清单:
myList = ["Toronto Maple Leafs", "New York Rangers"]
Run Code Online (Sandbox Code Playgroud)
使用endswith()方法,我想写一个if语句,检查myString是否以myList中的任何一个字符串结尾.我有基本的if语句,但我对我应该在括号中加入来检查这个问题感到困惑.
if myStr.endswith():
print("Success")
Run Code Online (Sandbox Code Playgroud) 我目前正在开发一个更新网页的Python脚本.但是运行主脚本会产生以下错误:
<res status='-1'><error message="'NoneType' object has no attribute 'endswith'"><![CDATA[
Traceback (most recent call last):
File "/path/to/file/ws_config.py", line XXXX, in Run
tests = TestList().tests
File "/path/to/file/ws_config.py", line XXXX, in __init__
UpdateTestGroup(None),
File "/path/to/file/ws_config.py", line XXXX, in __init__
test = CT.CurlTest(settings),
File "/path/to/file/config_tests.py", line XXXX, in __init__
self.params.path = os.path.join('/', os.path.join(params.dir, params.file))
File "/usr/lib/python2.6/posixpath.py", line 67, in join
elif path == '' or path.endswith('/'):
AttributeError: 'NoneType' object has no attribute 'endswith'
Run Code Online (Sandbox Code Playgroud)
我不能通过任何代码,因为太长了.我想要了解的是错误的位置或代码的哪一部分触发了AttributeError.你能帮我么???
我想过滤掉在列的字符串值中包含'*'的表的行.只检查该列.
string_name = c("aaaaa", "bbbbb", "ccccc", "dddd*", "eee*eee")
zz <- sapply(tx$variant_full_name, function(x) {substrRight(x, -1) =="*"})
Error in FUN(c("Agno I30N", "VP2 E17Q", "VP2 I204*", "VP3 I85F", "VP1 K73R", :
could not find function "substrRight"
Run Code Online (Sandbox Code Playgroud)
由此,zz的第4个值应该为TRUE.
在python中有字符串的endswith函数[string_s.endswith('*')]是否有类似于R的东西?
此外,它是否有问题,因为'*'作为一个字符,因为它意味着任何字符?grepl也没有用.
> grepl("*^",'dddd*')
[1] TRUE
> grepl("*^",'dddd')
[1] TRUE
Run Code Online (Sandbox Code Playgroud) 如果它结束,我需要修剪路径\
.
C:\Ravi\
Run Code Online (Sandbox Code Playgroud)
我需要换到
C:\Ravi
Run Code Online (Sandbox Code Playgroud)
我有一个路径不会结束的情况\
(然后它必须跳过).
我尝试过.EndsWith("\")
,但是当我有\\
而不是时,它失败了\
.
这可以在PowerShell中完成,而无需诉诸条件吗?
鉴于HTML包含:
<div tagname="779853cd-355b-4242-8399-dc15f95b3276_Destination" class="panel panel-default"></div>
Run Code Online (Sandbox Code Playgroud)
我们如何在XPath中编写以下表达式:
查找属性以字符串'Destination'结尾的<div>
元素tagname
我一直在寻找几天,我无法想出一些有用的东西.在众多中,我试过例如:
div[contains(@tagname, 'Destination')]
Run Code Online (Sandbox Code Playgroud) ends-with ×10
string ×5
python ×3
r ×2
startswith ×2
xpath ×2
c++ ×1
filepath ×1
html ×1
java ×1
javascript ×1
nonetype ×1
powershell ×1
python-2.7 ×1
python-3.x ×1
text-parsing ×1
xml ×1