ends-with

How to determine if a string “ends with” another string in R?

别说谁变了你拦得住时间么 提交于 2020-07-18 04:12:07
问题 I want to filter out the rows of a table which contain '*' in the string value of the column. Checking just that column. 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" The 4th value of zz should be TRUE by this. in python there is endswith function for strings [ string_s.endswith('*') ]

r dplyr ends_with multiple string matches

…衆ロ難τιáo~ 提交于 2020-01-01 06:34:08
问题 Can I use dplyr::select(ends_with) to select column names that fit any of multiple conditions. Considering my column names, I want to use ends with instead of contains or matches, because the strings I want to select are relevant at the end of the column name, but may also appear in the middle in others. For instance, df <- data.frame(a10 = 1:4, a11 = 5:8, a20 = 1:4, a12 = 5:8) I want to select columns that end with 1 or 2, to have only columns a11 and a12. Is select(ends_with) the best way

matching end of string

情到浓时终转凉″ 提交于 2019-12-19 11:43:07
问题 I'm looking for the best most efficient way to match the end of a single string with a value from a predefined list of strings. Something like my_str='QWERTY' my_lst=['QWE','QQQQ','TYE','YTR','TY'] match='TY' or match=['TY'] Under the restrictions len(my_lst) is known but arbitrary thus could be very long, probably around 30 elements in my_lst may have different len so I can't just check a defined last portion of my_str every time for my_str as well as the matching elements in my_lst they can

Powershell command to trim path if it ends with “\”

匆匆过客 提交于 2019-12-12 09:35:17
问题 I need to trim path if it ends with \ . C:\Ravi\ I need to change to C:\Ravi I have a case where path will not end with \ (Then it must skip). I tried with .EndsWith("\") , but it fails when I have \\ instead of \ . Can this be done in PowerShell without resorting to conditionals? 回答1: no need to overcomplicate "C:\Ravi\".trim('\') 回答2: Consider using TrimEnd instead (especially if you are working with UNC Path): "C:\Ravi\".TrimEnd('\') 回答3: You mention needing to differentiate between paths

How to see if a string ends with one of multiple characters

こ雲淡風輕ζ 提交于 2019-12-11 05:27:01
问题 I have this statement: string_tokens[-1].ends_with?(",") || string_tokens[-1].ends_with?("-") || string_tokens[-1].ends_with?("&") I would like to put all the tokens ( "," , "-" , "&" ) into a constant and simplify the above to ask, "does the string end with any of these characters", but I'm not sure how to do that. 回答1: Yes. CONST = %w(, - &).freeze string_tokens[-1].end_with?(*CONST) Usage: 'test,'.end_with?(*CONST) #=> true 'test&'.end_with?(*CONST) #=> true 'test-'.end_with?(*CONST) #=>

Powershell command to trim path if it ends with “\\”

狂风中的少年 提交于 2019-12-05 01:29:05
I need to trim path if it ends with \ . C:\Ravi\ I need to change to C:\Ravi I have a case where path will not end with \ (Then it must skip). I tried with .EndsWith("\") , but it fails when I have \\ instead of \ . Can this be done in PowerShell without resorting to conditionals? no need to overcomplicate "C:\Ravi\".trim('\') Consider using TrimEnd instead (especially if you are working with UNC Path): "C:\Ravi\".TrimEnd('\') You mention needing to differentiate between paths ending in "\" and "\\" and possibly handling those differently. While you can use .Trim("\") or .TrimEnd("\") to

How do I ignore case when using startsWith and endsWith in Java? [duplicate]

≯℡__Kan透↙ 提交于 2019-12-03 20:34:23
问题 This question already has answers here : startsWith() method of string ignoring case (7 answers) Closed 2 years ago . Here's my code: 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");

Regular Expression To Match String Not Starting With Or Ending With Spaces

走远了吗. 提交于 2019-12-02 03:08:01
问题 I need a regular expression that makes sure a string does not start with or end with a space. I don't care if it has a space in the "middle" just not at the beginning or the end. I have a regular expression that almost works: ^\S.*\S$ Here are some example results: "HELLO" (Match) "HEL LO" (Match) " HELLO" (No Match) "HELLO " (No Match) "H" (No Match) As you can see, the issue I am having is that when the string is only 1 character long ("H" in the example above) it doesn't return a match.

Regular Expression To Match String Not Starting With Or Ending With Spaces

吃可爱长大的小学妹 提交于 2019-12-02 02:10:19
I need a regular expression that makes sure a string does not start with or end with a space. I don't care if it has a space in the "middle" just not at the beginning or the end. I have a regular expression that almost works: ^\S.*\S$ Here are some example results: "HELLO" (Match) "HEL LO" (Match) " HELLO" (No Match) "HELLO " (No Match) "H" (No Match) As you can see, the issue I am having is that when the string is only 1 character long ("H" in the example above) it doesn't return a match. How do I modify my regular expression to handle the case where the string length is 1? Thank you NOTE - I

XPath for element whose attribute value ends with a specific string?

时光毁灭记忆、已成空白 提交于 2019-12-01 17:32:19
Given that the HTML contains: <div tagname="779853cd-355b-4242-8399-dc15f95b3276_Destination" class="panel panel-default"></div> How do we write the following expression in XPath: Find a <div> element whose tagname attribute ends with the string 'Destination' I've been searching for days and I can't come up with something that works. Among many, I tried for example: div[contains(@tagname, 'Destination')] XPath 2.0 //div[ends-with(@tagname, 'Destination')] XPath 1.0 //div[substring(@tagname,string-length(@tagname) -string-length('Destination') +1) = 'Destination'] XPath 2 or 3: There's always