Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

check if string contains substring

Like this:

if (str.indexOf("Yes") >= 0)
...or you can use the tilde operator:

if (~str.indexOf("Yes"))
This works because indexOf() returns -1 if the string wasn't found at all.

Note that this is case-sensitive.
If you want a case-insensitive search, you can write

if (str.toLowerCase().indexOf("yes") >= 0)
Or:

if (/yes/i.test(str))
Comment

check if string is substring of another string

function mutation(arr) {
  let first = arr[0];
  let second = arr[1];
  
  return first.indexOf(second) !== -1;
}

console.log(mutation(["hello", "hel"]));
Comment

Find If String Is Substring Of Another

#is target in base?

def findSubstring(base, target):
   match = ""
   for x in range(0, len(base)):
       substring = base[0:len(base)-x]
       if substring == target:
           print("there is a match")
           match = substring
            
   if match == "":
     return ""
   else:
     return match
      


print(findSubstring("aaaaaaa", "aaa"))
Comment

PREVIOUS NEXT
Code Example
Python :: from django.urls import reverse 
Python :: How to convert string to uppercase, lowercase and how to swapcase in python 
Python :: preprocessing image (pixel to vector conversion) 
Python :: convert set to list python time complexity method 3 
Python :: Python | Program to print duplicates from a list of integers 
Python :: pandas add mutliple columns 
Python :: python enum key string get 
Python :: Sending Data in Unstructured File Form 
Python :: get database image in dajngo 
Python :: mql5 python 
Python :: enumerate for string 
Python :: Comparison operators and conditional execution 
Python :: tweepy to dataframe 
Python :: python file operation 
Python :: Illustrate Different Set Operations 
Python :: django create view template 
Python :: travis deployment script for django applications to heroku 
Python :: how to input a string character into a numpy zeros imatrix n python 
Python :: how to use ttk themes 
Python :: how to write statements in python 
Python :: RuntimeError: input must have 3 dimensions, got 4 site:stackoverflow.com 
Python :: zoom in geopandas polot 
Python :: pygame do you need to use int() for positions 
Python :: pandas dataframe not able to change values 
Python :: getting month number in python 
Python :: scapy get packet destination port python 
Python :: python zahl abrunden 
Python :: lol infinite print in python 
Python :: how to add field to django forms createview 
Python :: pytube.exceptions.RegexMatchError: __init__: could not find match for ^w+W 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =