Relates to the task of finding a subset of data at the beginning of a set of data. Usually refers to strings but could be other types of data. Please accompany with a language specific tag.
Questions tagged [startswith]
412 questions
34
votes
2 answers
Xpath - Selecting attributes using starts-with
I am trying to write an xpath expression that selects all div tags that have an attribute id that start with CompanyCalendar. Below is a snippet of the HTML that I am looking at:

Marek
- 863
- 4
- 12
- 19
29
votes
4 answers
Elasticsearch "starts with" first word in phrases
I try to implement an A - Z navigation for my content with Elasticsearch.
What I need, is displaying all results which begins with e.g. a,b,c,... etc.
I've tried:
"query": {
"match_phrase_prefix" : {
"title" : {
"query"…

alin
- 533
- 2
- 5
- 9
28
votes
6 answers
Python: startswith any alpha character
How can I use the startswith function to match any alpha character [a-zA-Z]. For example I would like to do this:
if line.startswith(ALPHA):
Do Something

teggy
- 5,995
- 9
- 38
- 41
25
votes
1 answer
Why does string.StartsWith("\u2D2D") always return true?
I was fiddling around with parsing in C# and found that for every string I tried, string.StartsWith("\u2D2D") will return true. Why is that?
It seems it works with every char. Tried this code with .Net 4.5 the Debugger did not break.
for (char i =…

prydain
- 365
- 3
- 11
20
votes
4 answers
Why is function isprefix faster than Startswith in C#?
Does anyone know why C# (.NET)'s StartsWith function is considerably slower than IsPrefix?
Frantisek
20
votes
8 answers
Why do Strings start with a "" in Java?
Possible Duplicate:
Why does “abcd”.StartsWith(“”) return true?
Whilst debugging through some code I found a particular piece of my validation was using the .startsWith() method on the String class to check if a String started with a blank…

Jimmy
- 16,123
- 39
- 133
- 213
18
votes
1 answer
"aaaa".StartsWith("aaa") returns false
If this is not a bug, can anyone then explain the reason behind this behavior? Indeed it seems that every odd number of letters will return false:
string test =…

sondergard
- 3,184
- 1
- 16
- 25
17
votes
2 answers
LINQ to SQL query where a string StartsWith an element from a generic list
I'm looking to update one of my queries as the requirements for the search has changed. Originally, the user was to enter a single SKU and a mfg. date range to search the product catalog. So this is what I used.
DateTime startDate = ...;
DateTime…

Andy Evans
- 6,997
- 18
- 72
- 118
17
votes
3 answers
How to remove a string from a list that startswith prefix in python
I have this list of strings and some prefixes. I want to remove all the strings from the list that start with any of these prefixes. I tried:
prefixes = ('hello', 'bye')
list = ['hi', 'helloyou', 'holla', 'byeyou', 'hellooooo']
for word in list:
…

EerlijkeDame
- 477
- 3
- 8
- 18
16
votes
4 answers
jQuery - How to select value by attribute name starts with
I want to select attribute value by giving attribute name (only starts with)
For instance if we have html tag
I want to select the value from the attribute starts with data-
Thanks in…

user3111581
- 165
- 1
- 1
- 4
15
votes
3 answers
Use Python to remove lines in a files that start with an octothorpe?
This seems like a straight-forward question but I can't seem to pinpoint my problem. I am trying to delete all lines in a file that start with an octothorpe (#) except the first line. Here is the loop I am working with:
for i, line in…

drbunsen
- 10,139
- 21
- 66
- 94
15
votes
3 answers
Angular JS 'Startswith' custom filter
So I've been trying a while to make a custom filter that searches for the 'Startswith' parameters rather than the 'Contains'. Every filter that I've written haven't seem to work properly. Here is an example of what I'm trying to achieve --->…

Chris Pena
- 374
- 1
- 4
- 10
14
votes
3 answers
StartsWith method C# doesn't return TRUE
I read some values from MS SQL database and I like to make some operations on string. Here is the code I am using to check if some string starts with another string:
String input = "Основното jавно обвинителство денеска поднесе пријава против БМ…

vikifor
- 3,426
- 4
- 45
- 75
14
votes
3 answers
If any item of list starts with string?
I'm trying to check is any item of a list starts with a certain string. How could I do this with a for loop? IE:
anyStartsWith = False
for item in myList:
if item.startsWith('qwerty'):
anyStartsWith = True

tkbx
- 15,602
- 32
- 87
- 122
13
votes
6 answers
Determine if string starts with letters A through I
I've got a simple java assignment. I need to determine if a string starts with the letter A through I. I know i have to use string.startsWith(); but I don't want to write, if(string.startsWith("a")); all the way to I, it seems in efficient. Should I…

Archey
- 1,312
- 5
- 15
- 21