“indeks ciągu” Kod odpowiedzi

nieformacyjne

const beasts = ['ant', 'bison', 'camel', 'duck', 'bison'];

console.log(beasts.indexOf('bison'));
// expected output: 1
Ugliest Unicorn

indeks ciągu

# To find the index of a substring in another string
# Take for instance, below take two strings: str and substr. 

str="hello world"
substr="world"
 
prefix=${str%%$substr*}
index=${#prefix}
 
if [[ index -eq ${#str} ]];
then
    echo "Substring is not present in string."
else
    echo "Index of substring in string : $index"
fi

Mckynde

indeks łańcuchowy Python of

sentence = 'Python programming is fun.'

result = sentence.index('is fun')
print("Substring 'is fun':", result)

result = sentence.index('Java')
print("Substring 'Java':", result)
Healthy Heron

Znajdź pierwsze wystąpienie znaku w ciągu

// applies to C#
string S = "Any String At All"
int Sindex = S.indexOf("A") // accepts string or char arguments. 

// "Sindex" would be equal to "0", as the indexOf(); meathod returns
// the index position of the first occurance of the specified argument.

indeks ciągu

  s = 'Hello'
  len(s)   ## 5
  ## Chars are numbered starting with 0
  s[0]     ## 'H'
  s[1]     ## 'e'
  s[4]     ## 'o'  -- last char is at length-1
  s[5]     ## ERROR, index out of bounds
Precious Parrot

Odpowiedzi podobne do “indeks ciągu”

Pytania podobne do “indeks ciągu”

Więcej pokrewnych odpowiedzi na “indeks ciągu” w Shell/Bash

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu