substring

Find the nth occurrence of substring in a string

独自空忆成欢 提交于 2021-02-17 05:14:49
问题 This seems like it should be pretty trivial, but I am new at Python and want to do it the most Pythonic way. I want to find the index corresponding to the n'th occurrence of a substring within a string. There's got to be something equivalent to what I WANT to do which is mystring.find("substring", 2nd) How can you achieve this in Python? 回答1: Mark's iterative approach would be the usual way, I think. Here's an alternative with string-splitting, which can often be useful for finding-related

Trim a string to a specific number of characters in R

大兔子大兔子 提交于 2021-02-16 13:46:09
问题 I would like to trim a character vector to the first five characters in each element. In this example I would like to trim each number in string to the first five characters. I am sure there must be an easy way to do this. string<- c("3243423", "23423", "34243234", "2342", "32544532", "85678657") I would like to have a a vector c("32434", "23423", "34243", "2342", "32544", "85678") 回答1: The following works as well (didn't know about strtrim ) substring(string, 1, 5) 回答2: Figured it out. Hope

Substring in Java - length up to a value

淺唱寂寞╮ 提交于 2021-02-16 09:55:26
问题 I'm trying to make a substring which lets me have up to 6 letters of a surname, however what I have here seems to throw an error when it finds a surname of less than 6 letters, I have been looking for hours for a solution with no sucess :/ id = firstName.substring (0,1).toLowerCase() + secondName.substring (0,6).toLowerCase(); System.out.print ("Here is your ID number: " + id); It's the .substring(0,6) . I need it to be up to 6 letters not exactly 6. The error: Exception in thread "main" java

Powerquery, does string contain an item in a list

房东的猫 提交于 2021-02-11 16:11:28
问题 I would like to filter on whether multiple text columns ([Name], [GenericName], or [SimpleGenericName]) contains a substring from a list. The text is also mixed case so I need to do a Text.Lower([Column]) in there as well. I've tried the formula: = Table.SelectRows(#"Sorted Rows", each List.Contains(MED_NAME_LIST, Text.Lower([Name]))) However, this does not work as the Column [Name] does not exactly match those items in the list (e.g. it won't pick up "Methylprednisolone Tab" if the list

How correctly convert this String using substring() Java method?

浪尽此生 提交于 2021-02-11 15:13:53
问题 I have the following problem using the substring() Java function. I have to do the following operation: I have a String representing a date having the following form: 2014-12-27 ( YEARS-MONTH-DAY ). And I want convert it into a String like this: 20141227 (without the space betwen date component). So I have implemented the following method that use the substring() method to achieve this task: private String convertDate(String dataPar) { String convertedDate = dataPar.substring(0,3) + dataPar

How correctly convert this String using substring() Java method?

白昼怎懂夜的黑 提交于 2021-02-11 15:12:41
问题 I have the following problem using the substring() Java function. I have to do the following operation: I have a String representing a date having the following form: 2014-12-27 ( YEARS-MONTH-DAY ). And I want convert it into a String like this: 20141227 (without the space betwen date component). So I have implemented the following method that use the substring() method to achieve this task: private String convertDate(String dataPar) { String convertedDate = dataPar.substring(0,3) + dataPar

How can I remove a substring from a given String using Pandas

假装没事ソ 提交于 2021-02-11 15:10:31
问题 Recently I started to analyse a data frame and I want to remove all the substrings that don't contain ('Aparelho Celular','Internet (Serviços e Produtos)','Serviços Telefônicos Diversos','Telefonia Celular','Telefonia Comunitária ( PABX, DDR, Etc. )','Telefonia Fixa','TV por Assinatura','Televisão / Aparelho DVD / Filmadora','Telemarketing') But when I use this syntax- df = df[~df["GrupoAssunto"].str.contains('Aparelho Celular','Internet (Serviços e Produtos)','Serviços Telefônicos Diversos',

How can I remove a substring from a given String using Pandas

▼魔方 西西 提交于 2021-02-11 15:10:20
问题 Recently I started to analyse a data frame and I want to remove all the substrings that don't contain ('Aparelho Celular','Internet (Serviços e Produtos)','Serviços Telefônicos Diversos','Telefonia Celular','Telefonia Comunitária ( PABX, DDR, Etc. )','Telefonia Fixa','TV por Assinatura','Televisão / Aparelho DVD / Filmadora','Telemarketing') But when I use this syntax- df = df[~df["GrupoAssunto"].str.contains('Aparelho Celular','Internet (Serviços e Produtos)','Serviços Telefônicos Diversos',

Simple substring search (brute force)

心已入冬 提交于 2021-02-10 15:49:05
问题 I'm trying to make a simple substring search using the brute force technique but I'm getting an error which I can't see. I'm quite new to programming so please keep that in mind. The problem might be very simple. using System; using System.Collections; using System.Collections.Generic; namespace SubstringSearch { class Program { static void Main(string[] args) { Console.Write("Please enter some letters: "); string sequence = Console.ReadLine(); Console.Write("Enter the sequence you want to

A problem that I tried to solve with the help of strings and repetitive instructions, but on the console the result is not what I expected

删除回忆录丶 提交于 2021-02-10 14:31:00
问题 using System; class Program { static void Main(string[] args) { string candidateName = Console.ReadLine(); string input = Console.ReadLine(); int numberOfAdmittedPersons = Convert.ToInt32(input); string result = string.Empty; for (int i = 1; i <= numberOfAdmittedPersons; i++) { string listOfAllAdmittedPersons = Console.ReadLine(); { if (i != numberOfAdmittedPersons) { result += listOfAllAdmittedPersons; } } } if (result.Contains(candidateName)) { Console.WriteLine("true"); } else { Console