“índice de cadena” Código de respuesta

incomparar

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

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

índice de cadena

# 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

Índice de cadena de python de

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

Encuentre la primera aparición de carácter en la cadena

// 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.

índice de cadena

  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

Respuestas similares a “índice de cadena”

Preguntas similares a “índice de cadena”

Más respuestas relacionadas con “índice de cadena” en Shell/Bash

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código