All Questions

6771
votes
47answers
4235011 views

How to check whether a string contains a substring in JavaScript?

Usually I would expect a String.contains() method but there doesn't seem to be one. What is a reasonable way to check for this?
2176
votes
11answers
1909162 views

Does Python have a string 'contains' substring method?

I'm looking for a string.contains or string.indexof method in Python. I want to do: if not somestring.contains("blah"): continue
1449
votes
19answers
1164508 views

String contains in Bash

Using Bash, I have a string: string = "My string" How can I test if it contains another string? if [ $string ?? 'foo' ]; then echo "It's there!" fi Where ?? is my unknown operator. Do I use ec...
133
votes
12answers
185769 views

Replace part of a string with another string

Is it possible in C++ to replace part of a string with another string? Basically, I would like to do this: QString string("hello $name"); string.replace("$name", "Somename"); But I would like to u...
1074
votes
18answers
490551 views

How do I check if a string contains another string in Objective-C?

How can I check if a string (NSString) contains another smaller string? I was hoping for something like: NSString *string = @"hello bla bla"; NSLog(@"%d",[string containsSubstring:@"hello"]); But ...
75
votes
27answers
151531 views

Get substring between two strings PHP

I need a function that returns the substring between two words (or two characters). I'm wondering whether there is a php function that achieves that. I do not want to think about regex (well, I could ...
403
votes
20answers
706579 views

Extract substring in Bash

Given a filename in the form someletters_12345_moreleters.ext, I want to extract the 5 digits and put them into a variable. So to emphasize the point, I have a filename with x number of characters th...
140
votes
5answers
240958 views

Batch file: Find if substring is in string (not in a file)

In a batch file, I have a string abcdefg. I want to check if bcd is in the string. Unfortunately it seems all of the solutions I'm finding search a file for a substring, not a string for a substri...
38
votes
3answers
6503 views

Why substring slicing index out of range works in Python?

Why doesn't 'example'[999:9999] result in error? Since 'example'[9] does, what is the motivation behind it? From this behavior I can assume that 'example'[3] is, essentially/internally, not the same ...
124
votes
16answers
49212 views

What is the fastest substring search algorithm?

OK, so I don't sound like an idiot I'm going to state the problem/requirements more explicitly: Needle (pattern) and haystack (text to search) are both C-style null-terminated strings. No length inf...

Previous Next